<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The Django admin site &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../../index.html" />
    <link rel="up" title="contrib packages" href="../index.html" />
    <link rel="next" title="Admin actions" href="actions.html" />
    <link rel="prev" title="contrib packages" href="../index.html" />



 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="../index.html" title="&lt;tt class=&#34;docutils literal&#34;&gt;&lt;span class=&#34;pre&#34;&gt;contrib&lt;/span&gt;&lt;/tt&gt; packages">previous</a>
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="actions.html" title="Admin actions">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-admin-index">
            
  <div class="section" id="s-module-django.contrib.admin">
<span id="s-the-django-admin-site"></span><span id="module-django.contrib.admin"></span><span id="the-django-admin-site"></span><h1>The Django admin site<a class="headerlink" href="#module-django.contrib.admin" title="Permalink to this headline">¶</a></h1>
<p>One of the most powerful parts of Django is the automatic admin interface. It
reads metadata in your model to provide a powerful and production-ready
interface that content producers can immediately use to start adding content to
the site. In this document, we discuss how to activate, use and customize
Django&#8217;s admin interface.</p>
<div class="section" id="s-overview">
<span id="overview"></span><h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>The admin is enabled in the default project template used by
<a class="reference internal" href="../../django-admin.html#django-admin-startproject"><tt class="xref std std-djadmin docutils literal"><span class="pre">startproject</span></tt></a>.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> <p>In previous versions, the admin wasn&#8217;t enabled by default.</p>
</div>
<p>For reference, here are the requirements:</p>
<ol class="arabic simple">
<li>Add <tt class="docutils literal"><span class="pre">'django.contrib.admin'</span></tt> to your <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting.</li>
<li>The admin has four dependencies - <a class="reference internal" href="../../../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.auth</span></tt></a>,
<a class="reference internal" href="../contenttypes.html#module-django.contrib.contenttypes" title="django.contrib.contenttypes: Provides generic interface to installed models."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.contenttypes</span></tt></a>,
<a class="reference internal" href="../messages.html#module-django.contrib.messages" title="django.contrib.messages: Provides cookie- and session-based temporary message storage."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.messages</span></tt></a> and
<a class="reference internal" href="../../../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.sessions</span></tt></a>.  If these applications are not
in your <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> list, add them.</li>
<li>Add <tt class="docutils literal"><span class="pre">django.contrib.messages.context_processors.messages</span></tt> to
<a class="reference internal" href="../../settings.html#std:setting-TEMPLATE_CONTEXT_PROCESSORS"><tt class="xref std std-setting docutils literal"><span class="pre">TEMPLATE_CONTEXT_PROCESSORS</span></tt></a> as well as
<a class="reference internal" href="../../middleware.html#django.contrib.auth.middleware.AuthenticationMiddleware" title="django.contrib.auth.middleware.AuthenticationMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.auth.middleware.AuthenticationMiddleware</span></tt></a> and
<a class="reference internal" href="../../middleware.html#django.contrib.messages.middleware.MessageMiddleware" title="django.contrib.messages.middleware.MessageMiddleware"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.messages.middleware.MessageMiddleware</span></tt></a> to
<a class="reference internal" href="../../settings.html#std:setting-MIDDLEWARE_CLASSES"><tt class="xref std std-setting docutils literal"><span class="pre">MIDDLEWARE_CLASSES</span></tt></a>. (These are all active by default, so
you only need to do this if you&#8217;ve manually tweaked the settings.)</li>
<li>Determine which of your application&#8217;s models should be editable in the
admin interface.</li>
<li>For each of those models, optionally create a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class that
encapsulates the customized admin functionality and options for that
particular model.</li>
<li>Instantiate an <tt class="docutils literal"><span class="pre">AdminSite</span></tt> and tell it about each of your models and
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> classes.</li>
<li>Hook the <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instance into your URLconf.</li>
</ol>
<p>After you&#8217;ve taken these steps, you&#8217;ll be able to use your Django admin site
by visiting the URL you hooked it into (<tt class="docutils literal"><span class="pre">/admin/</span></tt>, by default).</p>
<div class="section" id="s-other-topics">
<span id="other-topics"></span><h3>Other topics<a class="headerlink" href="#other-topics" title="Permalink to this headline">¶</a></h3>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="actions.html">Admin actions</a></li>
<li class="toctree-l1"><a class="reference internal" href="admindocs.html">The Django admin documentation generator</a></li>
</ul>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p>For information about serving the static files (images, JavaScript, and
CSS) associated with the admin in production, see <a class="reference internal" href="../../../howto/deployment/wsgi/modwsgi.html#serving-files"><em>Serving files</em></a>.</p>
<p class="last">Having problems?  Try <a class="reference internal" href="../../../faq/admin.html"><em>FAQ: The admin</em></a>.</p>
</div>
</div>
</div>
<div class="section" id="s-modeladmin-objects">
<span id="modeladmin-objects"></span><h2><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> objects<a class="headerlink" href="#modeladmin-objects" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.admin.ModelAdmin">
<em class="property">class </em><tt class="descname">ModelAdmin</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class is the representation of a model in the admin
interface. Usually, these are stored in a file named <tt class="docutils literal"><span class="pre">admin.py</span></tt> in your
application. Let&#8217;s take a look at a very simple example of
the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">myproject.myapp.models</span> <span class="kn">import</span> <span class="n">Author</span>

<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">pass</span>
<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Author</span><span class="p">,</span> <span class="n">AuthorAdmin</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition-do-you-need-a-modeladmin-object-at-all admonition">
<p class="first admonition-title">Do you need a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> object at all?</p>
<p>In the preceding example, the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class doesn&#8217;t define any
custom values (yet). As a result, the default admin interface will be
provided. If you are happy with the default admin interface, you don&#8217;t
need to define a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> object at all &#8211; you can register the
model class without providing a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> description. The
preceding example could be simplified to:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">myproject.myapp.models</span> <span class="kn">import</span> <span class="n">Author</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Author</span><span class="p">)</span>
</pre></div>
</div>
</div>
</dd></dl>

<div class="section" id="s-the-register-decorator">
<span id="the-register-decorator"></span><h3>The register decorator<a class="headerlink" href="#the-register-decorator" title="Permalink to this headline">¶</a></h3>
<dl class="function">
<dt id="django.contrib.admin.register">
<tt class="descname">register</tt>(<em>*models</em><span class="optional">[</span>, <em>site=django.admin.sites.site</em><span class="optional">]</span>)<a class="headerlink" href="#django.contrib.admin.register" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>There is also a decorator for registering your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> classes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">Author</span>

<span class="nd">@admin.register</span><span class="p">(</span><span class="n">Author</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">pass</span>
</pre></div>
</div>
<p>It is given one or more model classes to register with the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>
and an optional keyword argument <tt class="docutils literal"><span class="pre">site</span></tt> if you are not using the default
<tt class="docutils literal"><span class="pre">AdminSite</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">Author</span><span class="p">,</span> <span class="n">Reader</span><span class="p">,</span> <span class="n">Editor</span>
<span class="kn">from</span> <span class="nn">myproject.admin_site</span> <span class="kn">import</span> <span class="n">custom_admin_site</span>

<span class="nd">@admin.register</span><span class="p">(</span><span class="n">Author</span><span class="p">,</span> <span class="n">Reader</span><span class="p">,</span> <span class="n">Editor</span><span class="p">,</span> <span class="n">site</span><span class="o">=</span><span class="n">custom_admin_site</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">pass</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="s-discovery-of-admin-files">
<span id="discovery-of-admin-files"></span><h3>Discovery of admin files<a class="headerlink" href="#discovery-of-admin-files" title="Permalink to this headline">¶</a></h3>
<p>When you put <tt class="docutils literal"><span class="pre">'django.contrib.admin'</span></tt> in your <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a>
setting, Django automatically looks for an <tt class="docutils literal"><span class="pre">admin</span></tt> module in each
application and imports it.</p>
<dl class="class">
<dt id="django.contrib.admin.apps.AdminConfig">
<em class="property">class </em><tt class="descclassname">apps.</tt><tt class="descname">AdminConfig</tt><a class="headerlink" href="#django.contrib.admin.apps.AdminConfig" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>This is the default <a class="reference internal" href="../../applications.html#django.apps.AppConfig" title="django.apps.AppConfig"><tt class="xref py py-class docutils literal"><span class="pre">AppConfig</span></tt></a> class for the admin.
It calls <a class="reference internal" href="#django.contrib.admin.autodiscover" title="django.contrib.admin.autodiscover"><tt class="xref py py-func docutils literal"><span class="pre">autodiscover()</span></tt></a> when Django starts.</p>
</dd></dl>

<dl class="class">
<dt id="django.contrib.admin.apps.SimpleAdminConfig">
<em class="property">class </em><tt class="descclassname">apps.</tt><tt class="descname">SimpleAdminConfig</tt><a class="headerlink" href="#django.contrib.admin.apps.SimpleAdminConfig" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>This class works like <a class="reference internal" href="#django.contrib.admin.apps.AdminConfig" title="django.contrib.admin.apps.AdminConfig"><tt class="xref py py-class docutils literal"><span class="pre">AdminConfig</span></tt></a>,
except it doesn&#8217;t call <a class="reference internal" href="#django.contrib.admin.autodiscover" title="django.contrib.admin.autodiscover"><tt class="xref py py-func docutils literal"><span class="pre">autodiscover()</span></tt></a>.</p>
</dd></dl>

<dl class="function">
<dt id="django.contrib.admin.autodiscover">
<tt class="descname">autodiscover</tt>()<a class="reference internal" href="../../../_modules/django/contrib/admin.html#autodiscover"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.contrib.admin.autodiscover" title="Permalink to this definition">¶</a></dt>
<dd><p>This function attempts to import an <tt class="docutils literal"><span class="pre">admin</span></tt> module in each installed
application. Such modules are expected to register models with the admin.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p>Previous versions of Django recommended calling this function directly
in the URLconf. As of Django 1.7 this isn&#8217;t needed anymore.
<a class="reference internal" href="#django.contrib.admin.apps.AdminConfig" title="django.contrib.admin.apps.AdminConfig"><tt class="xref py py-class docutils literal"><span class="pre">AdminConfig</span></tt></a> takes care of running
the auto-discovery automatically.</p>
</div>
</dd></dl>

<p>If you are using a custom <tt class="docutils literal"><span class="pre">AdminSite</span></tt>, it is common to import all of the
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> subclasses into your code and register them to the custom
<tt class="docutils literal"><span class="pre">AdminSite</span></tt>. In that case, in order to disable auto-discovery, you should
put <tt class="docutils literal"><span class="pre">'django.contrib.admin.apps.SimpleAdminConfig'</span></tt> instead of
<tt class="docutils literal"><span class="pre">'django.contrib.admin'</span></tt> in your <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p>In previous versions, the admin needed to be instructed to look for
<tt class="docutils literal"><span class="pre">admin.py</span></tt> files with <a class="reference internal" href="#django.contrib.admin.autodiscover" title="django.contrib.admin.autodiscover"><tt class="xref py py-func docutils literal"><span class="pre">autodiscover()</span></tt></a>.
As of Django 1.7, auto-discovery is enabled by default and must be
explicitly disabled when it&#8217;s undesirable.</p>
</div>
</div>
<div class="section" id="s-modeladmin-options">
<span id="modeladmin-options"></span><h3><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> options<a class="headerlink" href="#modeladmin-options" title="Permalink to this headline">¶</a></h3>
<p>The <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> is very flexible. It has several options for dealing with
customizing the interface. All options are defined on the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>
subclass:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">date_hierarchy</span> <span class="o">=</span> <span class="s">&#39;pub_date&#39;</span>
</pre></div>
</div>
<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.actions">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">actions</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.actions" title="Permalink to this definition">¶</a></dt>
<dd><p>A list of actions to make available on the change list page. See
<a class="reference internal" href="actions.html"><em>Admin actions</em></a> for details.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.actions_on_top">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">actions_on_top</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.actions_on_top" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.actions_on_bottom">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">actions_on_bottom</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.actions_on_bottom" title="Permalink to this definition">¶</a></dt>
<dd><p>Controls where on the page the actions bar appears. By default, the admin
changelist displays actions at the top of the page (<tt class="docutils literal"><span class="pre">actions_on_top</span> <span class="pre">=</span> <span class="pre">True;</span>
<span class="pre">actions_on_bottom</span> <span class="pre">=</span> <span class="pre">False</span></tt>).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.actions_selection_counter">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">actions_selection_counter</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.actions_selection_counter" title="Permalink to this definition">¶</a></dt>
<dd><p>Controls whether a selection counter is displayed next to the action dropdown.
By default, the admin changelist will display it
(<tt class="docutils literal"><span class="pre">actions_selection_counter</span> <span class="pre">=</span> <span class="pre">True</span></tt>).</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.date_hierarchy">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">date_hierarchy</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.date_hierarchy" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">date_hierarchy</span></tt> to the name of a <tt class="docutils literal"><span class="pre">DateField</span></tt> or <tt class="docutils literal"><span class="pre">DateTimeField</span></tt>
in your model, and the change list page will include a date-based drilldown
navigation by that field.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">date_hierarchy</span> <span class="o">=</span> <span class="s">&#39;pub_date&#39;</span>
</pre></div>
</div>
<p>This will intelligently populate itself based on available data,
e.g. if all the dates are in one month, it&#8217;ll show the day-level
drill-down only.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><tt class="docutils literal"><span class="pre">date_hierarchy</span></tt> uses <a class="reference internal" href="../../models/querysets.html#django.db.models.query.QuerySet.datetimes" title="django.db.models.query.QuerySet.datetimes"><tt class="xref py py-meth docutils literal"><span class="pre">QuerySet.datetimes()</span></tt></a> internally. Please refer
to its documentation for some caveats when time zone support is
enabled (<a class="reference internal" href="../../settings.html#std:setting-USE_TZ"><tt class="xref std std-setting docutils literal"><span class="pre">USE_TZ</span> <span class="pre">=</span> <span class="pre">True</span></tt></a>).</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.exclude">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">exclude</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.exclude" title="Permalink to this definition">¶</a></dt>
<dd><p>This attribute, if given, should be a list of field names to exclude from
the form.</p>
<p>For example, let&#8217;s consider the following model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Author</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
    <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
    <span class="n">birth_date</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">(</span><span class="n">blank</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">null</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>If you want a form for the <tt class="docutils literal"><span class="pre">Author</span></tt> model that includes only the <tt class="docutils literal"><span class="pre">name</span></tt>
and <tt class="docutils literal"><span class="pre">title</span></tt> fields, you would specify <tt class="docutils literal"><span class="pre">fields</span></tt> or <tt class="docutils literal"><span class="pre">exclude</span></tt> like
this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;title&#39;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">exclude</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;birth_date&#39;</span><span class="p">,)</span>
</pre></div>
</div>
<p>Since the Author model only has three fields, <tt class="docutils literal"><span class="pre">name</span></tt>, <tt class="docutils literal"><span class="pre">title</span></tt>, and
<tt class="docutils literal"><span class="pre">birth_date</span></tt>, the forms resulting from the above declarations will
contain exactly the same fields.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.fields" title="Permalink to this definition">¶</a></dt>
<dd><p>If you need to achieve simple changes in the layout of fields in the forms
of the &#8220;add&#8221; and &#8220;change&#8221; pages like only showing a subset of the available
fields, modifying their order or grouping them in rows you can use the
<tt class="docutils literal"><span class="pre">fields</span></tt> option (for more complex layout needs see the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">fieldsets</span></tt></a> option described in the next section). For
example, you could define a simpler version of the admin form for the
<a class="reference internal" href="../flatpages.html#django.contrib.flatpages.models.FlatPage" title="django.contrib.flatpages.models.FlatPage"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.flatpages.models.FlatPage</span></tt></a> model as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">FlatPageAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;url&#39;</span><span class="p">,</span> <span class="s">&#39;title&#39;</span><span class="p">,</span> <span class="s">&#39;content&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>In the above example, only the fields <tt class="docutils literal"><span class="pre">url</span></tt>, <tt class="docutils literal"><span class="pre">title</span></tt> and <tt class="docutils literal"><span class="pre">content</span></tt>
will be displayed, sequentially, in the form. <tt class="docutils literal"><span class="pre">fields</span></tt> can contain
values defined in <a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.readonly_fields</span></tt></a> to be displayed as
read-only.</p>
<p>The <tt class="docutils literal"><span class="pre">fields</span></tt> option, unlike <a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><tt class="xref py py-attr docutils literal"><span class="pre">list_display</span></tt></a>, may only
contain names of fields on the model or the form specified by
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.form" title="django.contrib.admin.ModelAdmin.form"><tt class="xref py py-attr docutils literal"><span class="pre">form</span></tt></a>. It may contain callables only if they are listed
in <a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">readonly_fields</span></tt></a>.</p>
<p>To display multiple fields on the same line, wrap those fields in their own
tuple. In this example, the <tt class="docutils literal"><span class="pre">url</span></tt> and <tt class="docutils literal"><span class="pre">title</span></tt> fields will display on the
same line and the <tt class="docutils literal"><span class="pre">content</span></tt> field will be displayed below them in its
own line:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">FlatPageAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">fields</span> <span class="o">=</span> <span class="p">((</span><span class="s">&#39;url&#39;</span><span class="p">,</span> <span class="s">&#39;title&#39;</span><span class="p">),</span> <span class="s">&#39;content&#39;</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition-note admonition">
<p class="first admonition-title">Note</p>
<p class="last">This <tt class="docutils literal"><span class="pre">fields</span></tt> option should not be confused with the <tt class="docutils literal"><span class="pre">fields</span></tt>
dictionary key that is within the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">fieldsets</span></tt></a> option,
as described in the next section.</p>
</div>
<p>If neither <tt class="docutils literal"><span class="pre">fields</span></tt> nor <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">fieldsets</span></tt></a> options are present,
Django will default to displaying each field that isn&#8217;t an <tt class="docutils literal"><span class="pre">AutoField</span></tt> and
has <tt class="docutils literal"><span class="pre">editable=True</span></tt>, in a single fieldset, in the same order as the fields
are defined in the model.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.fieldsets">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">fieldsets</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.fieldsets" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">fieldsets</span></tt> to control the layout of admin &#8220;add&#8221; and &#8220;change&#8221; pages.</p>
<p><tt class="docutils literal"><span class="pre">fieldsets</span></tt> is a list of two-tuples, in which each two-tuple represents a
<tt class="docutils literal"><span class="pre">&lt;fieldset&gt;</span></tt> on the admin form page. (A <tt class="docutils literal"><span class="pre">&lt;fieldset&gt;</span></tt> is a &#8220;section&#8221; of
the form.)</p>
<p>The two-tuples are in the format <tt class="docutils literal"><span class="pre">(name,</span> <span class="pre">field_options)</span></tt>, where <tt class="docutils literal"><span class="pre">name</span></tt>
is a string representing the title of the fieldset and <tt class="docutils literal"><span class="pre">field_options</span></tt> is
a dictionary of information about the fieldset, including a list of fields
to be displayed in it.</p>
<p>A full example, taken from the
<a class="reference internal" href="../flatpages.html#django.contrib.flatpages.models.FlatPage" title="django.contrib.flatpages.models.FlatPage"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.flatpages.models.FlatPage</span></tt></a> model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">FlatPageAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">fieldsets</span> <span class="o">=</span> <span class="p">(</span>
        <span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="p">{</span>
            <span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;url&#39;</span><span class="p">,</span> <span class="s">&#39;title&#39;</span><span class="p">,</span> <span class="s">&#39;content&#39;</span><span class="p">,</span> <span class="s">&#39;sites&#39;</span><span class="p">)</span>
        <span class="p">}),</span>
        <span class="p">(</span><span class="s">&#39;Advanced options&#39;</span><span class="p">,</span> <span class="p">{</span>
            <span class="s">&#39;classes&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;collapse&#39;</span><span class="p">,),</span>
            <span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;enable_comments&#39;</span><span class="p">,</span> <span class="s">&#39;registration_required&#39;</span><span class="p">,</span> <span class="s">&#39;template_name&#39;</span><span class="p">)</span>
        <span class="p">}),</span>
    <span class="p">)</span>
</pre></div>
</div>
<p>This results in an admin page that looks like:</p>
<img alt="../../../_images/flatfiles_admin.png" src="../../../_images/flatfiles_admin.png" />
<p>If neither <tt class="docutils literal"><span class="pre">fieldsets</span></tt> nor <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">fields</span></tt></a> options are present,
Django will default to displaying each field that isn&#8217;t an <tt class="docutils literal"><span class="pre">AutoField</span></tt> and
has <tt class="docutils literal"><span class="pre">editable=True</span></tt>, in a single fieldset, in the same order as the fields
are defined in the model.</p>
<p>The <tt class="docutils literal"><span class="pre">field_options</span></tt> dictionary can have the following keys:</p>
<ul>
<li><dl class="first docutils">
<dt><tt class="docutils literal"><span class="pre">fields</span></tt></dt>
<dd><p class="first">A tuple of field names to display in this fieldset. This key is
required.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span>
<span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">,</span> <span class="s">&#39;address&#39;</span><span class="p">,</span> <span class="s">&#39;city&#39;</span><span class="p">,</span> <span class="s">&#39;state&#39;</span><span class="p">),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>As with the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">fields</span></tt></a> option, to display multiple
fields on the same line, wrap those fields in their own tuple. In this
example, the <tt class="docutils literal"><span class="pre">first_name</span></tt> and <tt class="docutils literal"><span class="pre">last_name</span></tt> fields will display on
the same line:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span>
<span class="s">&#39;fields&#39;</span><span class="p">:</span> <span class="p">((</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">),</span> <span class="s">&#39;address&#39;</span><span class="p">,</span> <span class="s">&#39;city&#39;</span><span class="p">,</span> <span class="s">&#39;state&#39;</span><span class="p">),</span>
<span class="p">}</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">fields</span></tt> can contain values defined in
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">readonly_fields</span></tt></a> to be displayed as read-only.</p>
<p class="last">If you add the name of a callable to <tt class="docutils literal"><span class="pre">fields</span></tt>, the same rule applies
as with the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">fields</span></tt></a> option: the callable must be
listed in <a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">readonly_fields</span></tt></a>.</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><tt class="docutils literal"><span class="pre">classes</span></tt></dt>
<dd><p class="first">A list containing extra CSS classes to apply to the fieldset.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span>
<span class="s">&#39;classes&#39;</span><span class="p">:</span> <span class="p">(</span><span class="s">&#39;wide&#39;</span><span class="p">,</span> <span class="s">&#39;extrapretty&#39;</span><span class="p">),</span>
<span class="p">}</span>
</pre></div>
</div>
<p class="last">Two useful classes defined by the default admin site stylesheet are
<tt class="docutils literal"><span class="pre">collapse</span></tt> and <tt class="docutils literal"><span class="pre">wide</span></tt>. Fieldsets with the <tt class="docutils literal"><span class="pre">collapse</span></tt> style
will be initially collapsed in the admin and replaced with a small
&#8220;click to expand&#8221; link. Fieldsets with the <tt class="docutils literal"><span class="pre">wide</span></tt> style will be
given extra horizontal space.</p>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><tt class="docutils literal"><span class="pre">description</span></tt></dt>
<dd><p class="first">A string of optional extra text to be displayed at the top of each
fieldset, under the heading of the fieldset. This string is not
rendered for <a class="reference internal" href="#django.contrib.admin.TabularInline" title="django.contrib.admin.TabularInline"><tt class="xref py py-class docutils literal"><span class="pre">TabularInline</span></tt></a> due to its
layout.</p>
<p class="last">Note that this value is <em>not</em> HTML-escaped when it&#8217;s displayed in
the admin interface. This lets you include HTML if you so desire.
Alternatively you can use plain text and
<tt class="docutils literal"><span class="pre">django.utils.html.escape()</span></tt> to escape any HTML special
characters.</p>
</dd>
</dl>
</li>
</ul>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.filter_horizontal">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">filter_horizontal</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.filter_horizontal" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, a <a class="reference internal" href="../../models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><tt class="xref py py-class docutils literal"><span class="pre">ManyToManyField</span></tt></a> is displayed in
the admin site with a <tt class="docutils literal"><span class="pre">&lt;select</span> <span class="pre">multiple&gt;</span></tt>. However, multiple-select boxes
can be difficult to use when selecting many items. Adding a
<a class="reference internal" href="../../models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><tt class="xref py py-class docutils literal"><span class="pre">ManyToManyField</span></tt></a> to this list will instead use
a nifty unobtrusive JavaScript &#8220;filter&#8221; interface that allows searching
within the options. The unselected and selected options appear in two boxes
side by side. See <a class="reference internal" href="#django.contrib.admin.ModelAdmin.filter_vertical" title="django.contrib.admin.ModelAdmin.filter_vertical"><tt class="xref py py-attr docutils literal"><span class="pre">filter_vertical</span></tt></a> to use a vertical
interface.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.filter_vertical">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">filter_vertical</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.filter_vertical" title="Permalink to this definition">¶</a></dt>
<dd><p>Same as <a class="reference internal" href="#django.contrib.admin.ModelAdmin.filter_horizontal" title="django.contrib.admin.ModelAdmin.filter_horizontal"><tt class="xref py py-attr docutils literal"><span class="pre">filter_horizontal</span></tt></a>, but uses a vertical display
of the filter interface with the box of unselected options appearing above
the box of selected options.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.form">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">form</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.form" title="Permalink to this definition">¶</a></dt>
<dd><p>By default a <tt class="docutils literal"><span class="pre">ModelForm</span></tt> is dynamically created for your model. It is
used to create the form presented on both the add/change pages. You can
easily provide your own <tt class="docutils literal"><span class="pre">ModelForm</span></tt> to override any default form behavior
on the add/change pages. Alternatively, you can customize the default
form rather than specifying an entirely new one by using the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_form" title="django.contrib.admin.ModelAdmin.get_form"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.get_form()</span></tt></a> method.</p>
<p>For an example see the section <a class="reference internal" href="#admin-custom-validation"><em>Adding custom validation to the admin</em></a>.</p>
<div class="admonition-note admonition">
<p class="first admonition-title">Note</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p>If you define the <tt class="docutils literal"><span class="pre">Meta.model</span></tt> attribute on a
<a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a>, you must also define the
<tt class="docutils literal"><span class="pre">Meta.fields</span></tt> attribute (or the <tt class="docutils literal"><span class="pre">Meta.exclude</span></tt> attribute). However,
since the admin has its own way of defining fields, the <tt class="docutils literal"><span class="pre">Meta.fields</span></tt>
attribute will be ignored.</p>
<p class="last">If the <tt class="docutils literal"><span class="pre">ModelForm</span></tt> is only going to be used for the admin, the easiest
solution is to omit the <tt class="docutils literal"><span class="pre">Meta.model</span></tt> attribute, since <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>
will provide the correct model to use. Alternatively, you can set
<tt class="docutils literal"><span class="pre">fields</span> <span class="pre">=</span> <span class="pre">[]</span></tt> in the <tt class="docutils literal"><span class="pre">Meta</span></tt> class to satisfy the validation on the
<tt class="docutils literal"><span class="pre">ModelForm</span></tt>.</p>
</div>
<div class="admonition-note admonition">
<p class="first admonition-title">Note</p>
<p>If your <tt class="docutils literal"><span class="pre">ModelForm</span></tt> and <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> both define an <tt class="docutils literal"><span class="pre">exclude</span></tt>
option then <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> takes precedence:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">myapp.models</span> <span class="kn">import</span> <span class="n">Person</span>

<span class="k">class</span> <span class="nc">PersonForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">ModelForm</span><span class="p">):</span>

    <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">Person</span>
        <span class="n">exclude</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">]</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">exclude</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;age&#39;</span><span class="p">]</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">PersonForm</span>
</pre></div>
</div>
<p class="last">In the above example, the &#8220;age&#8221; field will be excluded but the &#8220;name&#8221;
field will be included in the generated form.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.formfield_overrides">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">formfield_overrides</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.formfield_overrides" title="Permalink to this definition">¶</a></dt>
<dd><p>This provides a quick-and-dirty way to override some of the
<a class="reference internal" href="../../forms/fields.html#django.forms.Field" title="django.forms.Field"><tt class="xref py py-class docutils literal"><span class="pre">Field</span></tt></a> options for use in the admin.
<tt class="docutils literal"><span class="pre">formfield_overrides</span></tt> is a dictionary mapping a field class to a dict of
arguments to pass to the field at construction time.</p>
<p>Since that&#8217;s a bit abstract, let&#8217;s look at a concrete example. The most
common use of <tt class="docutils literal"><span class="pre">formfield_overrides</span></tt> is to add a custom widget for a
certain type of field. So, imagine we&#8217;ve written a <tt class="docutils literal"><span class="pre">RichTextEditorWidget</span></tt>
that we&#8217;d like to use for large text fields instead of the default
<tt class="docutils literal"><span class="pre">&lt;textarea&gt;</span></tt>. Here&#8217;s how we&#8217;d do that:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="c"># Import our custom widget and our model from where they&#39;re defined</span>
<span class="kn">from</span> <span class="nn">myapp.widgets</span> <span class="kn">import</span> <span class="n">RichTextEditorWidget</span>
<span class="kn">from</span> <span class="nn">myapp.models</span> <span class="kn">import</span> <span class="n">MyModel</span>

<span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">formfield_overrides</span> <span class="o">=</span> <span class="p">{</span>
        <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">:</span> <span class="p">{</span><span class="s">&#39;widget&#39;</span><span class="p">:</span> <span class="n">RichTextEditorWidget</span><span class="p">},</span>
    <span class="p">}</span>
</pre></div>
</div>
<p>Note that the key in the dictionary is the actual field class, <em>not</em> a
string. The value is another dictionary; these arguments will be passed to
the form field&#8217;s <tt class="docutils literal"><span class="pre">__init__()</span></tt> method. See <a class="reference internal" href="../../forms/api.html"><em>The Forms API</em></a> for
details.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p>If you want to use a custom widget with a relation field (i.e.
<a class="reference internal" href="../../models/fields.html#django.db.models.ForeignKey" title="django.db.models.ForeignKey"><tt class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></tt></a> or
<a class="reference internal" href="../../models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><tt class="xref py py-class docutils literal"><span class="pre">ManyToManyField</span></tt></a>), make sure you haven&#8217;t
included that field&#8217;s name in <tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> or <tt class="docutils literal"><span class="pre">radio_fields</span></tt>.</p>
<p class="last"><tt class="docutils literal"><span class="pre">formfield_overrides</span></tt> won&#8217;t let you change the widget on relation
fields that have <tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> or <tt class="docutils literal"><span class="pre">radio_fields</span></tt> set. That&#8217;s
because <tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> and <tt class="docutils literal"><span class="pre">radio_fields</span></tt> imply custom widgets of
their own.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.inlines">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">inlines</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.inlines" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a> objects below as well as
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_formsets_with_inlines" title="django.contrib.admin.ModelAdmin.get_formsets_with_inlines"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.get_formsets_with_inlines()</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_display">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_display</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_display" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_display</span></tt> to control which fields are displayed on the change
list page of the admin.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If you don&#8217;t set <tt class="docutils literal"><span class="pre">list_display</span></tt>, the admin site will display a single
column that displays the <tt class="docutils literal"><span class="pre">__str__()</span></tt> (<tt class="docutils literal"><span class="pre">__unicode__()</span></tt> on Python 2)
representation of each object.</p>
<p>You have four possible values that can be used in <tt class="docutils literal"><span class="pre">list_display</span></tt>:</p>
<ul>
<li><p class="first">A field of the model. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">A callable that accepts one parameter for the model instance. For
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">upper_case_name</span><span class="p">(</span><span class="n">obj</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">first_name</span><span class="p">,</span> <span class="n">obj</span><span class="o">.</span><span class="n">last_name</span><span class="p">))</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
<span class="n">upper_case_name</span><span class="o">.</span><span class="n">short_description</span> <span class="o">=</span> <span class="s">&#39;Name&#39;</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="n">upper_case_name</span><span class="p">,)</span>
</pre></div>
</div>
</li>
<li><p class="first">A string representing an attribute on the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>. This
behaves same as the callable. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;upper_case_name&#39;</span><span class="p">,)</span>

    <span class="k">def</span> <span class="nf">upper_case_name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">obj</span><span class="o">.</span><span class="n">first_name</span><span class="p">,</span> <span class="n">obj</span><span class="o">.</span><span class="n">last_name</span><span class="p">))</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
    <span class="n">upper_case_name</span><span class="o">.</span><span class="n">short_description</span> <span class="o">=</span> <span class="s">&#39;Name&#39;</span>
</pre></div>
</div>
</li>
<li><p class="first">A string representing an attribute on the model. This behaves almost
the same as the callable, but <tt class="docutils literal"><span class="pre">self</span></tt> in this context is the model
instance. Here&#8217;s a full model example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">birthday</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">decade_born_in</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">birthday</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;%Y&#39;</span><span class="p">)[:</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="s">&quot;0&#39;s&quot;</span>
    <span class="n">decade_born_in</span><span class="o">.</span><span class="n">short_description</span> <span class="o">=</span> <span class="s">&#39;Birth decade&#39;</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;decade_born_in&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
</ul>
<p>A few special cases to note about <tt class="docutils literal"><span class="pre">list_display</span></tt>:</p>
<ul>
<li><p class="first">If the field is a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt>, Django will display the
<tt class="docutils literal"><span class="pre">__str__()</span></tt> (<tt class="docutils literal"><span class="pre">__unicode__()</span></tt> on Python 2) of the related object.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">ManyToManyField</span></tt> fields aren&#8217;t supported, because that would
entail executing a separate SQL statement for each row in the table.
If you want to do this nonetheless, give your model a custom method,
and add that method&#8217;s name to <tt class="docutils literal"><span class="pre">list_display</span></tt>. (See below for more
on custom methods in <tt class="docutils literal"><span class="pre">list_display</span></tt>.)</p>
</li>
<li><p class="first">If the field is a <tt class="docutils literal"><span class="pre">BooleanField</span></tt> or <tt class="docutils literal"><span class="pre">NullBooleanField</span></tt>, Django
will display a pretty &#8220;on&#8221; or &#8220;off&#8221; icon instead of <tt class="docutils literal"><span class="pre">True</span></tt> or
<tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</li>
<li><p class="first">If the string given is a method of the model, <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> or a
callable, Django will HTML-escape the output by default. If you&#8217;d
rather not escape the output of the method, give the method an
<tt class="docutils literal"><span class="pre">allow_tags</span></tt> attribute whose value is <tt class="docutils literal"><span class="pre">True</span></tt>. However, to avoid an
XSS vulnerability, you should use <a class="reference internal" href="../../utils.html#django.utils.html.format_html" title="django.utils.html.format_html"><tt class="xref py py-func docutils literal"><span class="pre">format_html()</span></tt></a>
to escape user-provided inputs.</p>
<p>Here&#8217;s a full example model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.utils.html</span> <span class="kn">import</span> <span class="n">format_html</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">color_code</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">colored_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">format_html</span><span class="p">(</span><span class="s">&#39;&lt;span style=&quot;color: #{0};&quot;&gt;{1} {2}&lt;/span&gt;&#39;</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">color_code</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">first_name</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">last_name</span><span class="p">)</span>

    <span class="n">colored_name</span><span class="o">.</span><span class="n">allow_tags</span> <span class="o">=</span> <span class="bp">True</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">,</span> <span class="s">&#39;colored_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">If the string given is a method of the model, <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> or a
callable that returns True or False Django will display a pretty
&#8220;on&#8221; or &#8220;off&#8221; icon if you give the method a <tt class="docutils literal"><span class="pre">boolean</span></tt> attribute
whose value is <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
<p>Here&#8217;s a full example model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">birthday</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">born_in_fifties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">birthday</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;%Y&#39;</span><span class="p">)[:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;195&#39;</span>
    <span class="n">born_in_fifties</span><span class="o">.</span><span class="n">boolean</span> <span class="o">=</span> <span class="bp">True</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;born_in_fifties&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">The <tt class="docutils literal"><span class="pre">__str__()</span></tt> (<tt class="docutils literal"><span class="pre">__unicode__()</span></tt> on Python 2) method is just
as valid in <tt class="docutils literal"><span class="pre">list_display</span></tt> as any other model method, so it&#8217;s
perfectly OK to do this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;__str__&#39;</span><span class="p">,</span> <span class="s">&#39;some_other_field&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">Usually, elements of <tt class="docutils literal"><span class="pre">list_display</span></tt> that aren&#8217;t actual database
fields can&#8217;t be used in sorting (because Django does all the sorting
at the database level).</p>
<p>However, if an element of <tt class="docutils literal"><span class="pre">list_display</span></tt> represents a certain
database field, you can indicate this fact by setting the
<tt class="docutils literal"><span class="pre">admin_order_field</span></tt> attribute of the item.</p>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.utils.html</span> <span class="kn">import</span> <span class="n">format_html</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">color_code</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">colored_first_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">format_html</span><span class="p">(</span><span class="s">&#39;&lt;span style=&quot;color: #{0};&quot;&gt;{1}&lt;/span&gt;&#39;</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">color_code</span><span class="p">,</span>
                           <span class="bp">self</span><span class="o">.</span><span class="n">first_name</span><span class="p">)</span>

    <span class="n">colored_first_name</span><span class="o">.</span><span class="n">allow_tags</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="n">colored_first_name</span><span class="o">.</span><span class="n">admin_order_field</span> <span class="o">=</span> <span class="s">&#39;first_name&#39;</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;colored_first_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The above will tell Django to order by the <tt class="docutils literal"><span class="pre">first_name</span></tt> field when
trying to sort by <tt class="docutils literal"><span class="pre">colored_first_name</span></tt> in the admin.</p>
<div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>To indicate descending order with <tt class="docutils literal"><span class="pre">admin_order_field</span></tt> you can use a
hyphen prefix on the field name. Using the above example, this would
look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">colored_first_name</span><span class="o">.</span><span class="n">admin_order_field</span> <span class="o">=</span> <span class="s">&#39;-first_name&#39;</span>
</pre></div>
</div>
</li>
<li><p class="first">Elements of <tt class="docutils literal"><span class="pre">list_display</span></tt> can also be properties. Please note however,
that due to the way properties work in Python, setting
<tt class="docutils literal"><span class="pre">short_description</span></tt> on a property is only possible when using the
<tt class="docutils literal"><span class="pre">property()</span></tt> function and <strong>not</strong> with the <tt class="docutils literal"><span class="pre">&#64;property</span></tt> decorator.</p>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">first_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
    <span class="n">last_name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">my_property</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">first_name</span> <span class="o">+</span> <span class="s">&#39; &#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_name</span>
    <span class="n">my_property</span><span class="o">.</span><span class="n">short_description</span> <span class="o">=</span> <span class="s">&quot;Full name of the person&quot;</span>

    <span class="n">full_name</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">my_property</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;full_name&#39;</span><span class="p">,)</span>
</pre></div>
</div>
</li>
<li><div class="first versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>The field names in <tt class="docutils literal"><span class="pre">list_display</span></tt> will also appear as CSS classes in
the HTML output, in the form of <tt class="docutils literal"><span class="pre">column-&lt;field_name&gt;</span></tt> on each <tt class="docutils literal"><span class="pre">&lt;th&gt;</span></tt>
element. This can be used to set column widths in a CSS file for example.</p>
</li>
<li><p class="first">Django will try to interpret every element of <tt class="docutils literal"><span class="pre">list_display</span></tt> in this
order:</p>
<ul class="simple">
<li>A field of the model.</li>
<li>A callable.</li>
<li>A string representing a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> attribute.</li>
<li>A string representing a model attribute.</li>
</ul>
<p>For example if you have <tt class="docutils literal"><span class="pre">first_name</span></tt> as a model field and
as a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> attribute, the model field will be used.</p>
</li>
</ul>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_display_links">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_display_links</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_display_links" title="Permalink to this definition">¶</a></dt>
<dd><p>Use <tt class="docutils literal"><span class="pre">list_display_links</span></tt> to control if and which fields in
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><tt class="xref py py-attr docutils literal"><span class="pre">list_display</span></tt></a> should be linked to the &#8220;change&#8221; page for an object.</p>
<p>By default, the change list page will link the first column &#8211; the first
field specified in <tt class="docutils literal"><span class="pre">list_display</span></tt> &#8211; to the change page for each item.
But <tt class="docutils literal"><span class="pre">list_display_links</span></tt> lets you change this:</p>
<ul>
<li><p class="first">Set it to <tt class="docutils literal"><span class="pre">None</span></tt> to get no links at all.</p>
</li>
<li><p class="first">Set it to a list or tuple of fields (in the same format as
<tt class="docutils literal"><span class="pre">list_display</span></tt>) whose columns you want converted to links.</p>
<p>You can specify one or many fields. As long as the fields appear in
<tt class="docutils literal"><span class="pre">list_display</span></tt>, Django doesn&#8217;t care how many (or how few) fields are
linked. The only requirement is that if you want to use
<tt class="docutils literal"><span class="pre">list_display_links</span></tt> in this fashion, you must define <tt class="docutils literal"><span class="pre">list_display</span></tt>.</p>
</li>
</ul>
<p>In this example, the <tt class="docutils literal"><span class="pre">first_name</span></tt> and <tt class="docutils literal"><span class="pre">last_name</span></tt> fields will be
linked on the change list page:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">,</span> <span class="s">&#39;birthday&#39;</span><span class="p">)</span>
    <span class="n">list_display_links</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;first_name&#39;</span><span class="p">,</span> <span class="s">&#39;last_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>In this example, the change list page grid will have no links:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">AuditEntryAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;timestamp&#39;</span><span class="p">,</span> <span class="s">&#39;message&#39;</span><span class="p">)</span>
    <span class="n">list_display_links</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p><tt class="docutils literal"><span class="pre">None</span></tt> was added as a valid <tt class="docutils literal"><span class="pre">list_display_links</span></tt> value.</p>
</div>
</dd></dl>

<span class="target" id="admin-list-editable"></span><dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_editable">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_editable</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_editable" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_editable</span></tt> to a list of field names on the model which will
allow editing on the change list page. That is, fields listed in
<tt class="docutils literal"><span class="pre">list_editable</span></tt> will be displayed as form widgets on the change list
page, allowing users to edit and save multiple rows at once.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p><tt class="docutils literal"><span class="pre">list_editable</span></tt> interacts with a couple of other options in
particular ways; you should note the following rules:</p>
<ul class="simple">
<li>Any field in <tt class="docutils literal"><span class="pre">list_editable</span></tt> must also be in <tt class="docutils literal"><span class="pre">list_display</span></tt>.
You can&#8217;t edit a field that&#8217;s not displayed!</li>
<li>The same field can&#8217;t be listed in both <tt class="docutils literal"><span class="pre">list_editable</span></tt> and
<tt class="docutils literal"><span class="pre">list_display_links</span></tt> &#8211; a field can&#8217;t be both a form and
a link.</li>
</ul>
<p class="last">You&#8217;ll get a validation error if either of these rules are broken.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_filter">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_filter</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_filter</span></tt> to activate filters in the right sidebar of the change
list page of the admin, as illustrated in the following screenshot:</p>
<img alt="../../../_images/users_changelist.png" src="../../../_images/users_changelist.png" />
<p><tt class="docutils literal"><span class="pre">list_filter</span></tt> should be a list or tuple of elements, where each element
should be of one of the following types:</p>
<ul>
<li><p class="first">a field name, where the specified field should be either a
<tt class="docutils literal"><span class="pre">BooleanField</span></tt>, <tt class="docutils literal"><span class="pre">CharField</span></tt>, <tt class="docutils literal"><span class="pre">DateField</span></tt>, <tt class="docutils literal"><span class="pre">DateTimeField</span></tt>,
<tt class="docutils literal"><span class="pre">IntegerField</span></tt>, <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt>, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_filter</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;is_staff&#39;</span><span class="p">,</span> <span class="s">&#39;company&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>Field names in <tt class="docutils literal"><span class="pre">list_filter</span></tt> can also span relations
using the <tt class="docutils literal"><span class="pre">__</span></tt> lookup, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">UserAdmin</span><span class="p">):</span>
    <span class="n">list_filter</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;company__name&#39;</span><span class="p">,)</span>
</pre></div>
</div>
</li>
<li><p class="first">a class inheriting from <tt class="docutils literal"><span class="pre">django.contrib.admin.SimpleListFilter</span></tt>,
which you need to provide the <tt class="docutils literal"><span class="pre">title</span></tt> and <tt class="docutils literal"><span class="pre">parameter_name</span></tt>
attributes to and override the <tt class="docutils literal"><span class="pre">lookups</span></tt> and <tt class="docutils literal"><span class="pre">queryset</span></tt> methods,
e.g.:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">date</span>

<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">ugettext_lazy</span> <span class="k">as</span> <span class="n">_</span>

<span class="k">class</span> <span class="nc">DecadeBornListFilter</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">SimpleListFilter</span><span class="p">):</span>
    <span class="c"># Human-readable title which will be displayed in the</span>
    <span class="c"># right admin sidebar just above the filter options.</span>
    <span class="n">title</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;decade born&#39;</span><span class="p">)</span>

    <span class="c"># Parameter for the filter that will be used in the URL query.</span>
    <span class="n">parameter_name</span> <span class="o">=</span> <span class="s">&#39;decade&#39;</span>

    <span class="k">def</span> <span class="nf">lookups</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">model_admin</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a list of tuples. The first element in each</span>
<span class="sd">        tuple is the coded value for the option that will</span>
<span class="sd">        appear in the URL query. The second element is the</span>
<span class="sd">        human-readable name for the option that will appear</span>
<span class="sd">        in the right sidebar.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">(</span>
            <span class="p">(</span><span class="s">&#39;80s&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;in the eighties&#39;</span><span class="p">)),</span>
            <span class="p">(</span><span class="s">&#39;90s&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;in the nineties&#39;</span><span class="p">)),</span>
        <span class="p">)</span>

    <span class="k">def</span> <span class="nf">queryset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">queryset</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the filtered queryset based on the value</span>
<span class="sd">        provided in the query string and retrievable via</span>
<span class="sd">        `self.value()`.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># Compare the requested value (either &#39;80s&#39; or &#39;90s&#39;)</span>
        <span class="c"># to decide how to filter the queryset.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;80s&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">queryset</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">birthday__gte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1980</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                                    <span class="n">birthday__lte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1989</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">31</span><span class="p">))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;90s&#39;</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">queryset</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">birthday__gte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1990</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                                    <span class="n">birthday__lte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1999</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">31</span><span class="p">))</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_filter</span> <span class="o">=</span> <span class="p">(</span><span class="n">DecadeBornListFilter</span><span class="p">,)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>As a convenience, the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> object is passed to the
<tt class="docutils literal"><span class="pre">lookups</span></tt> and <tt class="docutils literal"><span class="pre">queryset</span></tt> methods, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">AuthDecadeBornListFilter</span><span class="p">(</span><span class="n">DecadeBornListFilter</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">lookups</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">model_admin</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">AuthDecadeBornListFilter</span><span class="p">,</span>
                <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">lookups</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">model_admin</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">queryset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">queryset</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">AuthDecadeBornListFilter</span><span class="p">,</span>
                <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">queryset</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">queryset</span><span class="p">)</span>
</pre></div>
</div>
<p>Also as a convenience, the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> object is passed to
the <tt class="docutils literal"><span class="pre">lookups</span></tt> method, for example if you want to base the
lookups on the available data:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">AdvancedDecadeBornListFilter</span><span class="p">(</span><span class="n">DecadeBornListFilter</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">lookups</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">model_admin</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Only show the lookups if there actually is</span>
<span class="sd">        anyone born in the corresponding decades.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">qs</span> <span class="o">=</span> <span class="n">model_admin</span><span class="o">.</span><span class="n">get_queryset</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">qs</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">birthday__gte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1980</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                      <span class="n">birthday__lte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1989</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">31</span><span class="p">))</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
            <span class="k">yield</span> <span class="p">(</span><span class="s">&#39;80s&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;in the eighties&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">qs</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">birthday__gte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1990</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
                      <span class="n">birthday__lte</span><span class="o">=</span><span class="n">date</span><span class="p">(</span><span class="mi">1999</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">31</span><span class="p">))</span><span class="o">.</span><span class="n">exists</span><span class="p">():</span>
            <span class="k">yield</span> <span class="p">(</span><span class="s">&#39;90s&#39;</span><span class="p">,</span> <span class="n">_</span><span class="p">(</span><span class="s">&#39;in the nineties&#39;</span><span class="p">))</span>
</pre></div>
</div>
</div>
</li>
<li><p class="first">a tuple, where the first element is a field name and the second
element is a class inheriting from
<tt class="docutils literal"><span class="pre">django.contrib.admin.FieldListFilter</span></tt>, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_filter</span> <span class="o">=</span> <span class="p">(</span>
        <span class="p">(</span><span class="s">&#39;is_staff&#39;</span><span class="p">,</span> <span class="n">admin</span><span class="o">.</span><span class="n">BooleanFieldListFilter</span><span class="p">),</span>
    <span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <tt class="docutils literal"><span class="pre">FieldListFilter</span></tt> API is considered internal and might be
changed.</p>
</div>
</li>
</ul>
<p>It is possible to specify a custom template for rendering a list filter:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">FilterWithCustomTemplate</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">SimpleListFilter</span><span class="p">):</span>
    <span class="n">template</span> <span class="o">=</span> <span class="s">&quot;custom_template.html&quot;</span>
</pre></div>
</div>
<p>See the default template provided by django (<tt class="docutils literal"><span class="pre">admin/filter.html</span></tt>) for
a concrete example.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_max_show_all">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_max_show_all</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_max_show_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_max_show_all</span></tt> to control how many items can appear on a &#8220;Show
all&#8221; admin change list page. The admin will display a &#8220;Show all&#8221; link on the
change list only if the total result count is less than or equal to this
setting. By default, this is set to <tt class="docutils literal"><span class="pre">200</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_per_page">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_per_page</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_per_page" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_per_page</span></tt> to control how many items appear on each paginated
admin change list page. By default, this is set to <tt class="docutils literal"><span class="pre">100</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.list_select_related">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">list_select_related</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.list_select_related" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">list_select_related</span></tt> to tell Django to use
<a class="reference internal" href="../../models/querysets.html#django.db.models.query.QuerySet.select_related" title="django.db.models.query.QuerySet.select_related"><tt class="xref py py-meth docutils literal"><span class="pre">select_related()</span></tt></a> in retrieving
the list of objects on the admin change list page. This can save you a
bunch of database queries.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p>The value should be either a boolean, a list or a tuple. Default is
<tt class="docutils literal"><span class="pre">False</span></tt>.</p>
<p>When value is <tt class="docutils literal"><span class="pre">True</span></tt>, <tt class="docutils literal"><span class="pre">select_related()</span></tt> will always be called. When
value is set to <tt class="docutils literal"><span class="pre">False</span></tt>, Django will look at <tt class="docutils literal"><span class="pre">list_display</span></tt> and call
<tt class="docutils literal"><span class="pre">select_related()</span></tt> if any <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> is present.</p>
<p>If you need more fine-grained control, use a tuple (or list) as value for
<tt class="docutils literal"><span class="pre">list_select_related</span></tt>. Empty tuple will prevent Django from calling
<tt class="docutils literal"><span class="pre">select_related</span></tt> at all. Any other tuple will be passed directly to
<tt class="docutils literal"><span class="pre">select_related</span></tt> as parameters. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_select_related</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;author&#39;</span><span class="p">,</span> <span class="s">&#39;category&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>will call <tt class="docutils literal"><span class="pre">select_related('author',</span> <span class="pre">'category')</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.ordering">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">ordering</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.ordering" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">ordering</span></tt> to specify how lists of objects should be ordered in the
Django admin views. This should be a list or tuple in the same format as a
model&#8217;s <a class="reference internal" href="../../models/options.html#django.db.models.Options.ordering" title="django.db.models.Options.ordering"><tt class="xref py py-attr docutils literal"><span class="pre">ordering</span></tt></a> parameter.</p>
<p>If this isn&#8217;t provided, the Django admin will use the model&#8217;s default
ordering.</p>
<p>If you need to specify a dynamic order (for example depending on user or
language) you can implement a <a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_ordering" title="django.contrib.admin.ModelAdmin.get_ordering"><tt class="xref py py-meth docutils literal"><span class="pre">get_ordering()</span></tt></a> method.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.paginator">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">paginator</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.paginator" title="Permalink to this definition">¶</a></dt>
<dd><p>The paginator class to be used for pagination. By default,
<a class="reference internal" href="../../../topics/pagination.html#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">django.core.paginator.Paginator</span></tt></a> is used. If the custom paginator
class doesn&#8217;t have the same constructor interface as
<a class="reference internal" href="../../../topics/pagination.html#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">django.core.paginator.Paginator</span></tt></a>, you will also need to
provide an implementation for <a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_paginator" title="django.contrib.admin.ModelAdmin.get_paginator"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.get_paginator()</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.prepopulated_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">prepopulated_fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.prepopulated_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">prepopulated_fields</span></tt> to a dictionary mapping field names to the
fields it should prepopulate from:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">prepopulated_fields</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;slug&quot;</span><span class="p">:</span> <span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,)}</span>
</pre></div>
</div>
<p>When set, the given fields will use a bit of JavaScript to populate from
the fields assigned. The main use for this functionality is to
automatically generate the value for <tt class="docutils literal"><span class="pre">SlugField</span></tt> fields from one or more
other fields. The generated value is produced by concatenating the values
of the source fields, and then by transforming that result into a valid
slug (e.g. substituting dashes for spaces).</p>
<p><tt class="docutils literal"><span class="pre">prepopulated_fields</span></tt> doesn&#8217;t accept <tt class="docutils literal"><span class="pre">DateTimeField</span></tt>, <tt class="docutils literal"><span class="pre">ForeignKey</span></tt>,
nor <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt> fields.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.preserve_filters">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">preserve_filters</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.preserve_filters" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>The admin now preserves filters on the list view after creating, editing
or deleting an object. You can restore the previous behavior of clearing
filters by setting this attribute to <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.radio_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">radio_fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.radio_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, Django&#8217;s admin uses a select-box interface (&lt;select&gt;) for
fields that are <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or have <tt class="docutils literal"><span class="pre">choices</span></tt> set. If a field is
present in <tt class="docutils literal"><span class="pre">radio_fields</span></tt>, Django will use a radio-button interface
instead. Assuming <tt class="docutils literal"><span class="pre">group</span></tt> is a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> on the <tt class="docutils literal"><span class="pre">Person</span></tt> model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">radio_fields</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;group&quot;</span><span class="p">:</span> <span class="n">admin</span><span class="o">.</span><span class="n">VERTICAL</span><span class="p">}</span>
</pre></div>
</div>
<p>You have the choice of using <tt class="docutils literal"><span class="pre">HORIZONTAL</span></tt> or <tt class="docutils literal"><span class="pre">VERTICAL</span></tt> from the
<tt class="docutils literal"><span class="pre">django.contrib.admin</span></tt> module.</p>
<p>Don&#8217;t include a field in <tt class="docutils literal"><span class="pre">radio_fields</span></tt> unless it&#8217;s a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or has
<tt class="docutils literal"><span class="pre">choices</span></tt> set.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.raw_id_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">raw_id_fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.raw_id_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, Django&#8217;s admin uses a select-box interface (&lt;select&gt;) for
fields that are <tt class="docutils literal"><span class="pre">ForeignKey</span></tt>. Sometimes you don&#8217;t want to incur the
overhead of having to select all the related instances to display in the
drop-down.</p>
<p><tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> is a list of fields you would like to change
into an <tt class="docutils literal"><span class="pre">Input</span></tt> widget for either a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or
<tt class="docutils literal"><span class="pre">ManyToManyField</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">raw_id_fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;newspaper&quot;</span><span class="p">,)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> <tt class="docutils literal"><span class="pre">Input</span></tt> widget should contain a primary key if the
field is a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or a comma separated list of values if the field
is a <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt>.  The <tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> widget shows a magnifying
glass button next to the field which allows users to search for and select
a value:</p>
<img alt="../../../_images/raw_id_fields.png" src="../../../_images/raw_id_fields.png" />
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.readonly_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">readonly_fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>By default the admin shows all fields as editable. Any fields in this
option (which should be a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt>) will display its data
as-is and non-editable; they are also excluded from the
<a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a> used for creating and editing. Note that
when specifying <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fields</span></tt></a> or <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fieldsets</span></tt></a>
the read-only fields must be present to be shown (they are ignored
otherwise).</p>
<p>If <tt class="docutils literal"><span class="pre">readonly_fields</span></tt> is used without defining explicit ordering through
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fields</span></tt></a> or <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fieldsets</span></tt></a> they will be
added last after all editable fields.</p>
<p>A read-only field can not only display data from a model&#8217;s field, it can
also display the output of a model&#8217;s method or a method of the
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class itself. This is very similar to the way
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.list_display</span></tt></a> behaves. This provides an easy way to use
the admin interface to provide feedback on the status of the objects being
edited, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.utils.html</span> <span class="kn">import</span> <span class="n">format_html_join</span>
<span class="kn">from</span> <span class="nn">django.utils.safestring</span> <span class="kn">import</span> <span class="n">mark_safe</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">readonly_fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;address_report&#39;</span><span class="p">,)</span>

    <span class="k">def</span> <span class="nf">address_report</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">):</span>
        <span class="c"># assuming get_full_address() returns a list of strings</span>
        <span class="c"># for each line of the address and you want to separate each</span>
        <span class="c"># line by a linebreak</span>
        <span class="k">return</span> <span class="n">format_html_join</span><span class="p">(</span>
            <span class="n">mark_safe</span><span class="p">(</span><span class="s">&#39;&lt;br/&gt;&#39;</span><span class="p">),</span>
            <span class="s">&#39;{0}&#39;</span><span class="p">,</span>
            <span class="p">((</span><span class="n">line</span><span class="p">,)</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">instance</span><span class="o">.</span><span class="n">get_full_address</span><span class="p">()),</span>
        <span class="p">)</span> <span class="ow">or</span> <span class="s">&quot;&lt;span class=&#39;errors&#39;&gt;I can&#39;t determine this address.&lt;/span&gt;&quot;</span>

    <span class="c"># short_description functions like a model field&#39;s verbose_name</span>
    <span class="n">address_report</span><span class="o">.</span><span class="n">short_description</span> <span class="o">=</span> <span class="s">&quot;Address&quot;</span>
    <span class="c"># in this example, we have used HTML tags in the output</span>
    <span class="n">address_report</span><span class="o">.</span><span class="n">allow_tags</span> <span class="o">=</span> <span class="bp">True</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.save_as">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">save_as</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.save_as" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">save_as</span></tt> to enable a &#8220;save as&#8221; feature on admin change forms.</p>
<p>Normally, objects have three save options: &#8220;Save&#8221;, &#8220;Save and continue
editing&#8221; and &#8220;Save and add another&#8221;. If <tt class="docutils literal"><span class="pre">save_as</span></tt> is <tt class="docutils literal"><span class="pre">True</span></tt>, &#8220;Save
and add another&#8221; will be replaced by a &#8220;Save as&#8221; button.</p>
<p>&#8220;Save as&#8221; means the object will be saved as a new object (with a new ID),
rather than the old object.</p>
<p>By default, <tt class="docutils literal"><span class="pre">save_as</span></tt> is set to <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.save_on_top">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">save_on_top</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.save_on_top" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">save_on_top</span></tt> to add save buttons across the top of your admin change
forms.</p>
<p>Normally, the save buttons appear only at the bottom of the forms. If you
set <tt class="docutils literal"><span class="pre">save_on_top</span></tt>, the buttons will appear both on the top and the
bottom.</p>
<p>By default, <tt class="docutils literal"><span class="pre">save_on_top</span></tt> is set to <tt class="docutils literal"><span class="pre">False</span></tt>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.search_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">search_fields</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.search_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>Set <tt class="docutils literal"><span class="pre">search_fields</span></tt> to enable a search box on the admin change list page.
This should be set to a list of field names that will be searched whenever
somebody submits a search query in that text box.</p>
<p>These fields should be some kind of text field, such as <tt class="docutils literal"><span class="pre">CharField</span></tt> or
<tt class="docutils literal"><span class="pre">TextField</span></tt>. You can also perform a related lookup on a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or
<tt class="docutils literal"><span class="pre">ManyToManyField</span></tt> with the lookup API &#8220;follow&#8221; notation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">search_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;foreign_key__related_fieldname&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>For example, if you have a blog entry with an author, the following
definition would enable search blog entries by the email address of the
author:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">search_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;user__email&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>When somebody does a search in the admin search box, Django splits the
search query into words and returns all objects that contain each of the
words, case insensitive, where each word must be in at least one of
<tt class="docutils literal"><span class="pre">search_fields</span></tt>. For example, if <tt class="docutils literal"><span class="pre">search_fields</span></tt> is set to
<tt class="docutils literal"><span class="pre">['first_name',</span> <span class="pre">'last_name']</span></tt> and a user searches for <tt class="docutils literal"><span class="pre">john</span> <span class="pre">lennon</span></tt>,
Django will do the equivalent of this SQL <tt class="docutils literal"><span class="pre">WHERE</span></tt> clause:</p>
<div class="highlight-python"><div class="highlight"><pre>WHERE (first_name ILIKE &#39;%john%&#39; OR last_name ILIKE &#39;%john%&#39;)
AND (first_name ILIKE &#39;%lennon%&#39; OR last_name ILIKE &#39;%lennon%&#39;)
</pre></div>
</div>
<p>For faster and/or more restrictive searches, prefix the field name
with an operator:</p>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">^</span></tt></dt>
<dd><p class="first">Matches the beginning of the field. For example, if <tt class="docutils literal"><span class="pre">search_fields</span></tt>
is set to <tt class="docutils literal"><span class="pre">['^first_name',</span> <span class="pre">'^last_name']</span></tt> and a user searches for
<tt class="docutils literal"><span class="pre">john</span> <span class="pre">lennon</span></tt>, Django will do the equivalent of this SQL <tt class="docutils literal"><span class="pre">WHERE</span></tt>
clause:</p>
<div class="highlight-python"><div class="highlight"><pre>WHERE (first_name ILIKE &#39;john%&#39; OR last_name ILIKE &#39;john%&#39;)
AND (first_name ILIKE &#39;lennon%&#39; OR last_name ILIKE &#39;lennon%&#39;)
</pre></div>
</div>
<p class="last">This query is more efficient than the normal <tt class="docutils literal"><span class="pre">'%john%'</span></tt> query,
because the database only needs to check the beginning of a column&#8217;s
data, rather than seeking through the entire column&#8217;s data. Plus, if
the column has an index on it, some databases may be able to use the
index for this query, even though it&#8217;s a <tt class="docutils literal"><span class="pre">LIKE</span></tt> query.</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">=</span></tt></dt>
<dd><p class="first">Matches exactly, case-insensitive. For example, if
<tt class="docutils literal"><span class="pre">search_fields</span></tt> is set to <tt class="docutils literal"><span class="pre">['=first_name',</span> <span class="pre">'=last_name']</span></tt> and
a user searches for <tt class="docutils literal"><span class="pre">john</span> <span class="pre">lennon</span></tt>, Django will do the equivalent
of this SQL <tt class="docutils literal"><span class="pre">WHERE</span></tt> clause:</p>
<div class="highlight-python"><div class="highlight"><pre>WHERE (first_name ILIKE &#39;john&#39; OR last_name ILIKE &#39;john&#39;)
AND (first_name ILIKE &#39;lennon&#39; OR last_name ILIKE &#39;lennon&#39;)
</pre></div>
</div>
<p class="last">Note that the query input is split by spaces, so, following this
example, it&#8217;s currently not possible to search for all records in which
<tt class="docutils literal"><span class="pre">first_name</span></tt> is exactly <tt class="docutils literal"><span class="pre">'john</span> <span class="pre">winston'</span></tt> (containing a space).</p>
</dd>
<dt><tt class="docutils literal"><span class="pre">&#64;</span></tt></dt>
<dd>Performs a full-text match. This is like the default search method but
uses an index. Currently this is only available for MySQL.</dd>
</dl>
<p>If you need to customize search you can use
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_search_results" title="django.contrib.admin.ModelAdmin.get_search_results"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.get_search_results()</span></tt></a> to provide additional or alternate
search behavior.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.view_on_site">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">view_on_site</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.view_on_site" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>Set <tt class="docutils literal"><span class="pre">view_on_site</span></tt> to control whether or not to display the &#8220;View on site&#8221; link.
This link should bring you to a URL where you can display the saved object.</p>
<p>This value can be either a boolean flag or a callable. If <tt class="docutils literal"><span class="pre">True</span></tt> (the
default), the object&#8217;s <a class="reference internal" href="../../models/instances.html#django.db.models.Model.get_absolute_url" title="django.db.models.Model.get_absolute_url"><tt class="xref py py-meth docutils literal"><span class="pre">get_absolute_url()</span></tt></a>
method will be used to generate the url.</p>
<p>If your model has a <a class="reference internal" href="../../models/instances.html#django.db.models.Model.get_absolute_url" title="django.db.models.Model.get_absolute_url"><tt class="xref py py-meth docutils literal"><span class="pre">get_absolute_url()</span></tt></a> method
but you don&#8217;t want the &#8220;View on site&#8221; button to appear, you only need to set
<tt class="docutils literal"><span class="pre">view_on_site</span></tt> to <tt class="docutils literal"><span class="pre">False</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">view_on_site</span> <span class="o">=</span> <span class="bp">False</span>
</pre></div>
</div>
<p>In case it is a callable, it accepts the model instance as a parameter.
For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.core.urlresolvers</span> <span class="kn">import</span> <span class="n">reverse</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">view_on_site</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">&#39;http://example.com&#39;</span> <span class="o">+</span> <span class="n">reverse</span><span class="p">(</span><span class="s">&#39;person-detail&#39;</span><span class="p">,</span>
                                              <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;slug&#39;</span><span class="p">:</span> <span class="n">obj</span><span class="o">.</span><span class="n">slug</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

<div class="section" id="s-custom-template-options">
<span id="custom-template-options"></span><h4>Custom template options<a class="headerlink" href="#custom-template-options" title="Permalink to this headline">¶</a></h4>
<p>The <a class="reference internal" href="#admin-overriding-templates"><em>Overriding admin templates</em></a> section describes how to override or extend
the default admin templates.  Use the following options to override the default
templates used by the <a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a> views:</p>
<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.add_form_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">add_form_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.add_form_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.add_view" title="django.contrib.admin.ModelAdmin.add_view"><tt class="xref py py-meth docutils literal"><span class="pre">add_view()</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.change_form_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">change_form_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.change_form_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.change_view" title="django.contrib.admin.ModelAdmin.change_view"><tt class="xref py py-meth docutils literal"><span class="pre">change_view()</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.change_list_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">change_list_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.change_list_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.changelist_view" title="django.contrib.admin.ModelAdmin.changelist_view"><tt class="xref py py-meth docutils literal"><span class="pre">changelist_view()</span></tt></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.delete_confirmation_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">delete_confirmation_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.delete_confirmation_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.delete_view" title="django.contrib.admin.ModelAdmin.delete_view"><tt class="xref py py-meth docutils literal"><span class="pre">delete_view()</span></tt></a> for displaying a
confirmation page when deleting one or more objects.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.delete_selected_confirmation_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">delete_selected_confirmation_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.delete_selected_confirmation_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by the <tt class="docutils literal"><span class="pre">delete_selected</span></tt> action method
for displaying a confirmation page when deleting one or more objects. See
the <a class="reference internal" href="actions.html"><em>actions documentation</em></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.ModelAdmin.object_history_template">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">object_history_template</tt><a class="headerlink" href="#django.contrib.admin.ModelAdmin.object_history_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template, used by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.history_view" title="django.contrib.admin.ModelAdmin.history_view"><tt class="xref py py-meth docutils literal"><span class="pre">history_view()</span></tt></a>.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-modeladmin-methods">
<span id="s-model-admin-methods"></span><span id="modeladmin-methods"></span><span id="model-admin-methods"></span><h3><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> methods<a class="headerlink" href="#modeladmin-methods" title="Permalink to this headline">¶</a></h3>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last"><a class="reference internal" href="#django.contrib.admin.ModelAdmin.save_model" title="django.contrib.admin.ModelAdmin.save_model"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.save_model()</span></tt></a> and <a class="reference internal" href="#django.contrib.admin.ModelAdmin.delete_model" title="django.contrib.admin.ModelAdmin.delete_model"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.delete_model()</span></tt></a> must
save/delete the object, they are not for veto purposes, rather they allow
you to perform extra operations.</p>
</div>
<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.save_model">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">save_model</tt>(<em>request</em>, <em>obj</em>, <em>form</em>, <em>change</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.save_model" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">save_model</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt>, a model instance,
a <tt class="docutils literal"><span class="pre">ModelForm</span></tt> instance and a boolean value based on whether it is adding
or changing the object. Here you can do any pre- or post-save operations.</p>
<p>For example to attach <tt class="docutils literal"><span class="pre">request.user</span></tt> to the object prior to saving:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">save_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">change</span><span class="p">):</span>
        <span class="n">obj</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span>
        <span class="n">obj</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.delete_model">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">delete_model</tt>(<em>request</em>, <em>obj</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.delete_model" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">delete_model</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and a model
instance. Use this method to do pre- or post-delete operations.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.save_formset">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">save_formset</tt>(<em>request</em>, <em>form</em>, <em>formset</em>, <em>change</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.save_formset" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">save_formset</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt>, the parent
<tt class="docutils literal"><span class="pre">ModelForm</span></tt> instance and a boolean value based on whether it is adding or
changing the parent object.</p>
<p>For example, to attach <tt class="docutils literal"><span class="pre">request.user</span></tt> to each changed formset
model instance:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">save_formset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">formset</span><span class="p">,</span> <span class="n">change</span><span class="p">):</span>
        <span class="n">instances</span> <span class="o">=</span> <span class="n">formset</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">commit</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">instances</span><span class="p">:</span>
            <span class="n">instance</span><span class="o">.</span><span class="n">user</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span>
            <span class="n">instance</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
        <span class="n">formset</span><span class="o">.</span><span class="n">save_m2m</span><span class="p">()</span>
</pre></div>
</div>
<p>See also <a class="reference internal" href="../../../topics/forms/modelforms.html#saving-objects-in-the-formset"><em>Saving objects in the formset</em></a>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_ordering">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_ordering</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_ordering" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_ordering</span></tt> method takes a``request`` as parameter and
is expected to return a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> for ordering similar
to the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.ordering" title="django.contrib.admin.ModelAdmin.ordering"><tt class="xref py py-attr docutils literal"><span class="pre">ordering</span></tt></a> attribute. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">get_ordering</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;rank&#39;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">[</span><span class="s">&#39;name&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_search_results">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_search_results</tt>(<em>request</em>, <em>queryset</em>, <em>search_term</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_search_results" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>The <tt class="docutils literal"><span class="pre">get_search_results</span></tt> method modifies the list of objects displayed in
to those that match the provided search term. It accepts the request, a
queryset that applies the current filters, and the user-provided search term.
It returns a tuple containing a queryset modified to implement the search, and
a boolean indicating if the results may contain duplicates.</p>
<p>The default implementation searches the fields named in <a class="reference internal" href="#django.contrib.admin.ModelAdmin.search_fields" title="django.contrib.admin.ModelAdmin.search_fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.search_fields</span></tt></a>.</p>
<p>This method may be overridden with your own custom search method. For
example, you might wish to search by an integer field, or use an external
tool such as Solr or Haystack. You must establish if the queryset changes
implemented by your search method may introduce duplicates into the results,
and return <tt class="docutils literal"><span class="pre">True</span></tt> in the second element of the return value.</p>
<p>For example, to enable search by integer field, you could use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">list_display</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">)</span>
    <span class="n">search_fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">,)</span>

    <span class="k">def</span> <span class="nf">get_search_results</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">queryset</span><span class="p">,</span> <span class="n">search_term</span><span class="p">):</span>
        <span class="n">queryset</span><span class="p">,</span> <span class="n">use_distinct</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">PersonAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_search_results</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">queryset</span><span class="p">,</span> <span class="n">search_term</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">search_term_as_int</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">search_term</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">queryset</span> <span class="o">|=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">age</span><span class="o">=</span><span class="n">search_term_as_int</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">queryset</span><span class="p">,</span> <span class="n">use_distinct</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.save_related">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">save_related</tt>(<em>request</em>, <em>form</em>, <em>formsets</em>, <em>change</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.save_related" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">save_related</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt>, the parent
<tt class="docutils literal"><span class="pre">ModelForm</span></tt> instance, the list of inline formsets and a boolean value
based on whether the parent is being added or changed. Here you can do any
pre- or post-save operations for objects related to the parent. Note
that at this point the parent object and its form have already been saved.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_readonly_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_readonly_fields</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_readonly_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_readonly_fields</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and the
<tt class="docutils literal"><span class="pre">obj</span></tt> being edited (or <tt class="docutils literal"><span class="pre">None</span></tt> on an add form) and is expected to return
a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> of field names that will be displayed as read-only,
as described above in the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.readonly_fields</span></tt></a> section.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_prepopulated_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_prepopulated_fields</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_prepopulated_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_prepopulated_fields</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and the
<tt class="docutils literal"><span class="pre">obj</span></tt> being edited (or <tt class="docutils literal"><span class="pre">None</span></tt> on an add form) and is expected to return
a <tt class="docutils literal"><span class="pre">dictionary</span></tt>, as described above in the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.prepopulated_fields" title="django.contrib.admin.ModelAdmin.prepopulated_fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.prepopulated_fields</span></tt></a>
section.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_list_display">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_list_display</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_list_display" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_list_display</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and is
expected to return a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> of field names that will be
displayed on the changelist view as described above in the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.list_display</span></tt></a> section.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_list_display_links">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_list_display_links</tt>(<em>request</em>, <em>list_display</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_list_display_links" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_list_display_links</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and
the <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> returned by <a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_list_display" title="django.contrib.admin.ModelAdmin.get_list_display"><tt class="xref py py-meth docutils literal"><span class="pre">ModelAdmin.get_list_display()</span></tt></a>.
It is expected to return either <tt class="docutils literal"><span class="pre">None</span></tt> or a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> of field
names on the changelist that will be linked to the change view, as described
in the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_display_links" title="django.contrib.admin.ModelAdmin.list_display_links"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.list_display_links</span></tt></a> section.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.7:</span> <p><tt class="docutils literal"><span class="pre">None</span></tt> was added as a valid <tt class="docutils literal"><span class="pre">get_list_display_links()</span></tt> return value.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_fields</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_fields" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The <tt class="docutils literal"><span class="pre">get_fields</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and the <tt class="docutils literal"><span class="pre">obj</span></tt>
being edited (or <tt class="docutils literal"><span class="pre">None</span></tt> on an add form) and is expected to return a list
of fields, as described above in the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fields</span></tt></a> section.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_fieldsets">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_fieldsets</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_fieldsets" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_fieldsets</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and the <tt class="docutils literal"><span class="pre">obj</span></tt>
being edited (or <tt class="docutils literal"><span class="pre">None</span></tt> on an add form) and is expected to return a list
of two-tuples, in which each two-tuple represents a <tt class="docutils literal"><span class="pre">&lt;fieldset&gt;</span></tt> on the
admin form page, as described above in the <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.fieldsets</span></tt></a> section.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_list_filter">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_list_filter</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_list_filter" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_list_filter</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and is expected
to return the same kind of sequence type as for the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_filter" title="django.contrib.admin.ModelAdmin.list_filter"><tt class="xref py py-attr docutils literal"><span class="pre">list_filter</span></tt></a> attribute.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_search_fields">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_search_fields</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_search_fields" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The <tt class="docutils literal"><span class="pre">get_search_fields</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and is expected
to return the same kind of sequence type as for the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.search_fields" title="django.contrib.admin.ModelAdmin.search_fields"><tt class="xref py py-attr docutils literal"><span class="pre">search_fields</span></tt></a> attribute.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_inline_instances">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_inline_instances</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_inline_instances" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_inline_instances</span></tt> method is given the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> and the
<tt class="docutils literal"><span class="pre">obj</span></tt> being edited (or <tt class="docutils literal"><span class="pre">None</span></tt> on an add form) and is expected to return
a <tt class="docutils literal"><span class="pre">list</span></tt> or <tt class="docutils literal"><span class="pre">tuple</span></tt> of <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a>
objects, as described below in the <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a>
section. For example, the following would return inlines without the default
filtering based on add, change, and delete permissions:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">(</span><span class="n">MyInline</span><span class="p">,)</span>

    <span class="k">def</span> <span class="nf">get_inline_instances</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">inline</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">admin_site</span><span class="p">)</span> <span class="k">for</span> <span class="n">inline</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">inlines</span><span class="p">]</span>
</pre></div>
</div>
<p>If you override this method, make sure that the returned inlines are
instances of the classes defined in <a class="reference internal" href="#django.contrib.admin.ModelAdmin.inlines" title="django.contrib.admin.ModelAdmin.inlines"><tt class="xref py py-attr docutils literal"><span class="pre">inlines</span></tt></a> or you might encounter
a &#8220;Bad Request&#8221; error when adding related objects.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_urls">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_urls</tt>()<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_urls" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_urls</span></tt> method on a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> returns the URLs to be used for
that ModelAdmin in the same way as a URLconf.  Therefore you can extend
them as documented in <a class="reference internal" href="../../../topics/http/urls.html"><em>URL dispatcher</em></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_urls</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">urls</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_urls</span><span class="p">()</span>
        <span class="n">my_urls</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
            <span class="p">(</span><span class="s">r&#39;^my_view/$&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">my_view</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="k">return</span> <span class="n">my_urls</span> <span class="o">+</span> <span class="n">urls</span>

    <span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="c"># custom view which should return an HttpResponse</span>
        <span class="k">pass</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Notice that the custom patterns are included <em>before</em> the regular admin
URLs: the admin URL patterns are very permissive and will match nearly
anything, so you&#8217;ll usually want to prepend your custom URLs to the
built-in ones.</p>
<p class="last">In this example, <tt class="docutils literal"><span class="pre">my_view</span></tt> will be accessed at
<tt class="docutils literal"><span class="pre">/admin/myapp/mymodel/my_view/</span></tt> (assuming the admin URLs are included
at <tt class="docutils literal"><span class="pre">/admin/</span></tt>.)</p>
</div>
<p>However, the <tt class="docutils literal"><span class="pre">self.my_view</span></tt> function registered above suffers from two
problems:</p>
<ul class="simple">
<li>It will <em>not</em> perform any permission checks, so it will be accessible
to the general public.</li>
<li>It will <em>not</em> provide any header details to prevent caching. This means
if the page retrieves data from the database, and caching middleware is
active, the page could show outdated information.</li>
</ul>
<p>Since this is usually not what you want, Django provides a convenience
wrapper to check permissions and mark the view as non-cacheable. This
wrapper is <tt class="docutils literal"><span class="pre">AdminSite.admin_view()</span></tt> (i.e. <tt class="docutils literal"><span class="pre">self.admin_site.admin_view</span></tt>
inside a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> instance); use it like so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_urls</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">urls</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_urls</span><span class="p">()</span>
        <span class="n">my_urls</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
            <span class="p">(</span><span class="s">r&#39;^my_view/$&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">admin_site</span><span class="o">.</span><span class="n">admin_view</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">my_view</span><span class="p">))</span>
        <span class="p">)</span>
        <span class="k">return</span> <span class="n">my_urls</span> <span class="o">+</span> <span class="n">urls</span>
</pre></div>
</div>
<p>Notice the wrapped view in the fifth line above:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">r&#39;^my_view/$&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">admin_site</span><span class="o">.</span><span class="n">admin_view</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">my_view</span><span class="p">))</span>
</pre></div>
</div>
<p>This wrapping will protect <tt class="docutils literal"><span class="pre">self.my_view</span></tt> from unauthorized access and
will apply the <tt class="docutils literal"><span class="pre">django.views.decorators.cache.never_cache</span></tt> decorator to
make sure it is not cached if the cache middleware is active.</p>
<p>If the page is cacheable, but you still want the permission check to be
performed, you can pass a <tt class="docutils literal"><span class="pre">cacheable=True</span></tt> argument to
<tt class="docutils literal"><span class="pre">AdminSite.admin_view()</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">r&#39;^my_view/$&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">admin_site</span><span class="o">.</span><span class="n">admin_view</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">my_view</span><span class="p">,</span> <span class="n">cacheable</span><span class="o">=</span><span class="bp">True</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_form">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_form</tt>(<em>request</em>, <em>obj=None</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a> class for use in the admin add
and change views, see <a class="reference internal" href="#django.contrib.admin.ModelAdmin.add_view" title="django.contrib.admin.ModelAdmin.add_view"><tt class="xref py py-meth docutils literal"><span class="pre">add_view()</span></tt></a> and <a class="reference internal" href="#django.contrib.admin.ModelAdmin.change_view" title="django.contrib.admin.ModelAdmin.change_view"><tt class="xref py py-meth docutils literal"><span class="pre">change_view()</span></tt></a>.</p>
<p>The base implementation uses <a class="reference internal" href="../../forms/models.html#django.forms.models.modelform_factory" title="django.forms.models.modelform_factory"><tt class="xref py py-func docutils literal"><span class="pre">modelform_factory()</span></tt></a>
to subclass <a class="reference internal" href="#django.contrib.admin.ModelAdmin.form" title="django.contrib.admin.ModelAdmin.form"><tt class="xref py py-attr docutils literal"><span class="pre">form</span></tt></a>, modified by attributes such as <a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">fields</span></tt></a>
and <a class="reference internal" href="#django.contrib.admin.ModelAdmin.exclude" title="django.contrib.admin.ModelAdmin.exclude"><tt class="xref py py-attr docutils literal"><span class="pre">exclude</span></tt></a>. So, for example, if you wanted to offer additional
fields to superusers, you could swap in a different base form like so:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_form</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;form&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">MySuperuserForm</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p>You may also simply return a custom <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a> class
directly.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_formsets">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_formsets</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_formsets" title="Permalink to this definition">¶</a></dt>
<dd><div class="deprecated">
<p><span class="versionmodified">Deprecated since version 1.7: </span>Use <a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_formsets_with_inlines" title="django.contrib.admin.ModelAdmin.get_formsets_with_inlines"><tt class="xref py py-meth docutils literal"><span class="pre">get_formsets_with_inlines()</span></tt></a> instead.</p>
</div>
<p>Yields  <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a>s for use in admin add and change views.</p>
<p>For example if you wanted to display a particular inline only in the change
view, you could override <tt class="docutils literal"><span class="pre">get_formsets</span></tt> as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">MyInline</span><span class="p">,</span> <span class="n">SomeOtherInline</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">get_formsets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">inline</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_inline_instances</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
            <span class="c"># hide MyInline in the add view</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">inline</span><span class="p">,</span> <span class="n">MyInline</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">yield</span> <span class="n">inline</span><span class="o">.</span><span class="n">get_formset</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_formsets_with_inlines">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_formsets_with_inlines</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_formsets_with_inlines" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>Yields (<tt class="docutils literal"><span class="pre">FormSet</span></tt>, <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a>) pairs for use in admin add
and change views.</p>
<p>For example if you wanted to display a particular inline only in the change
view, you could override <tt class="docutils literal"><span class="pre">get_formsets_with_inlines</span></tt> as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span><span class="n">MyInline</span><span class="p">,</span> <span class="n">SomeOtherInline</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">get_formsets_with_inlines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">inline</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_inline_instances</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
            <span class="c"># hide MyInline in the add view</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">inline</span><span class="p">,</span> <span class="n">MyInline</span><span class="p">)</span> <span class="ow">and</span> <span class="n">obj</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">yield</span> <span class="n">inline</span><span class="o">.</span><span class="n">get_formset</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">),</span> <span class="n">inline</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.formfield_for_foreignkey">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">formfield_for_foreignkey</tt>(<em>db_field</em>, <em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.formfield_for_foreignkey" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">formfield_for_foreignkey</span></tt> method on a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> allows you to
override the default formfield for a foreign keys field. For example, to
return a subset of objects for this foreign key field based on the user:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">formfield_for_foreignkey</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">db_field</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">&quot;car&quot;</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s">&quot;queryset&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Car</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">owner</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">formfield_for_foreignkey</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<p>This uses the <tt class="docutils literal"><span class="pre">HttpRequest</span></tt> instance to filter the <tt class="docutils literal"><span class="pre">Car</span></tt> foreign key
field to only display the cars owned by the <tt class="docutils literal"><span class="pre">User</span></tt> instance.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.formfield_for_manytomany">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">formfield_for_manytomany</tt>(<em>db_field</em>, <em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.formfield_for_manytomany" title="Permalink to this definition">¶</a></dt>
<dd><p>Like the <tt class="docutils literal"><span class="pre">formfield_for_foreignkey</span></tt> method, the
<tt class="docutils literal"><span class="pre">formfield_for_manytomany</span></tt> method can be overridden to change the
default formfield for a many to many field. For example, if an owner can
own multiple cars and cars can belong to multiple owners &#8211; a many to
many relationship &#8211; you could filter the <tt class="docutils literal"><span class="pre">Car</span></tt> foreign key field to
only display the cars owned by the <tt class="docutils literal"><span class="pre">User</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">formfield_for_manytomany</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">db_field</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">&quot;cars&quot;</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s">&quot;queryset&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Car</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">owner</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">formfield_for_manytomany</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.formfield_for_choice_field">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">formfield_for_choice_field</tt>(<em>db_field</em>, <em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.formfield_for_choice_field" title="Permalink to this definition">¶</a></dt>
<dd><p>Like the <tt class="docutils literal"><span class="pre">formfield_for_foreignkey</span></tt> and <tt class="docutils literal"><span class="pre">formfield_for_manytomany</span></tt>
methods, the <tt class="docutils literal"><span class="pre">formfield_for_choice_field</span></tt> method can be overridden to
change the default formfield for a field that has declared choices. For
example, if the choices available to a superuser should be different than
those available to regular staff, you could proceed as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">formfield_for_choice_field</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">db_field</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s">&quot;status&quot;</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;choices&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
                <span class="p">(</span><span class="s">&#39;accepted&#39;</span><span class="p">,</span> <span class="s">&#39;Accepted&#39;</span><span class="p">),</span>
                <span class="p">(</span><span class="s">&#39;denied&#39;</span><span class="p">,</span> <span class="s">&#39;Denied&#39;</span><span class="p">),</span>
            <span class="p">)</span>
            <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
                <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;choices&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="p">((</span><span class="s">&#39;ready&#39;</span><span class="p">,</span> <span class="s">&#39;Ready for deployment&#39;</span><span class="p">),)</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">formfield_for_choice_field</span><span class="p">(</span><span class="n">db_field</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition-note admonition">
<p class="first admonition-title">Note</p>
<p class="last">Any <tt class="docutils literal"><span class="pre">choices</span></tt> attribute set on the formfield will limited to the form
field only. If the corresponding field on the model has choices set,
the choices provided to the form must be a valid subset of those
choices, otherwise the form submission will fail with
a <a class="reference internal" href="../../exceptions.html#django.core.exceptions.ValidationError" title="django.core.exceptions.ValidationError"><tt class="xref py py-exc docutils literal"><span class="pre">ValidationError</span></tt></a> when the model itself
is validated before saving.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_changelist">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_changelist</tt>(<em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_changelist" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <tt class="docutils literal"><span class="pre">Changelist</span></tt> class to be used for listing. By default,
<tt class="docutils literal"><span class="pre">django.contrib.admin.views.main.ChangeList</span></tt> is used. By inheriting this
class you can change the behavior of the listing.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_changelist_form">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_changelist_form</tt>(<em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_changelist_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a> class for use in the <tt class="docutils literal"><span class="pre">Formset</span></tt>
on the changelist page. To use a custom form, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">MyForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">ModelForm</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_changelist_form</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">MyForm</span>
</pre></div>
</div>
<div class="admonition-note admonition">
<p class="first admonition-title">Note</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6.</span> </div>
<p class="last">If you define the <tt class="docutils literal"><span class="pre">Meta.model</span></tt> attribute on a
<a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.ModelForm" title="django.forms.ModelForm"><tt class="xref py py-class docutils literal"><span class="pre">ModelForm</span></tt></a>, you must also define the
<tt class="docutils literal"><span class="pre">Meta.fields</span></tt> attribute (or the <tt class="docutils literal"><span class="pre">Meta.exclude</span></tt> attribute). However,
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> ignores this value, overriding it with the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_editable" title="django.contrib.admin.ModelAdmin.list_editable"><tt class="xref py py-attr docutils literal"><span class="pre">ModelAdmin.list_editable</span></tt></a> attribute. The easiest solution is to
omit the <tt class="docutils literal"><span class="pre">Meta.model</span></tt> attribute, since <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> will provide the
correct model to use.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_changelist_formset">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_changelist_formset</tt>(<em>request</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_changelist_formset" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="../../../topics/forms/modelforms.html#model-formsets"><em>ModelFormSet</em></a> class for use on the
changelist page if <a class="reference internal" href="#django.contrib.admin.ModelAdmin.list_editable" title="django.contrib.admin.ModelAdmin.list_editable"><tt class="xref py py-attr docutils literal"><span class="pre">list_editable</span></tt></a> is used. To use a
custom formset, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.forms.models</span> <span class="kn">import</span> <span class="n">BaseModelFormSet</span>

<span class="k">class</span> <span class="nc">MyAdminFormSet</span><span class="p">(</span><span class="n">BaseModelFormSet</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_changelist_formset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s">&#39;formset&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">MyAdminFormSet</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_changelist_formset</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.has_add_permission">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">has_add_permission</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.has_add_permission" title="Permalink to this definition">¶</a></dt>
<dd><p>Should return <tt class="docutils literal"><span class="pre">True</span></tt> if adding an object is permitted, <tt class="docutils literal"><span class="pre">False</span></tt>
otherwise.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.has_change_permission">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">has_change_permission</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.has_change_permission" title="Permalink to this definition">¶</a></dt>
<dd><p>Should return <tt class="docutils literal"><span class="pre">True</span></tt> if editing obj is permitted, <tt class="docutils literal"><span class="pre">False</span></tt> otherwise.
If obj is <tt class="docutils literal"><span class="pre">None</span></tt>, should return <tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt> to indicate whether
editing of objects of this type is permitted in general (e.g., <tt class="docutils literal"><span class="pre">False</span></tt>
will be interpreted as meaning that the current user is not permitted to
edit any object of this type).</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.has_delete_permission">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">has_delete_permission</tt>(<em>request</em>, <em>obj=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.has_delete_permission" title="Permalink to this definition">¶</a></dt>
<dd><p>Should return <tt class="docutils literal"><span class="pre">True</span></tt> if deleting obj is permitted, <tt class="docutils literal"><span class="pre">False</span></tt> otherwise.
If obj is <tt class="docutils literal"><span class="pre">None</span></tt>, should return <tt class="docutils literal"><span class="pre">True</span></tt> or <tt class="docutils literal"><span class="pre">False</span></tt> to indicate whether
deleting objects of this type is permitted in general (e.g., <tt class="docutils literal"><span class="pre">False</span></tt> will
be interpreted as meaning that the current user is not permitted to delete
any object of this type).</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_queryset">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_queryset</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_queryset" title="Permalink to this definition">¶</a></dt>
<dd><p>The <tt class="docutils literal"><span class="pre">get_queryset</span></tt> method on a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> returns a
<a class="reference internal" href="../../models/querysets.html#django.db.models.query.QuerySet" title="django.db.models.query.QuerySet"><tt class="xref py py-class docutils literal"><span class="pre">QuerySet</span></tt></a> of all model instances that
can be edited by the admin site. One use case for overriding this method
is to show objects owned by the logged-in user:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_queryset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="n">qs</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">get_queryset</span><span class="p">(</span><span class="n">request</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">is_superuser</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">qs</span>
        <span class="k">return</span> <span class="n">qs</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">author</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">user</span><span class="p">)</span>
</pre></div>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> <p>The <tt class="docutils literal"><span class="pre">get_queryset</span></tt> method was previously named <tt class="docutils literal"><span class="pre">queryset</span></tt>.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.message_user">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">message_user</tt>(<em>request</em>, <em>message</em>, <em>level=messages.INFO</em>, <em>extra_tags=''</em>, <em>fail_silently=False</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.message_user" title="Permalink to this definition">¶</a></dt>
<dd><p>Sends a message to the user using the <a class="reference internal" href="../messages.html#module-django.contrib.messages" title="django.contrib.messages: Provides cookie- and session-based temporary message storage."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.messages</span></tt></a>
backend.  See the <a class="reference internal" href="actions.html#custom-admin-action"><em>custom ModelAdmin example</em></a>.</p>
<p>Keyword arguments allow you to change the message level, add extra CSS
tags, or fail silently if the <tt class="docutils literal"><span class="pre">contrib.messages</span></tt> framework is not
installed. These keyword arguments match those for
<a class="reference internal" href="../messages.html#django.contrib.messages.add_message" title="django.contrib.messages.add_message"><tt class="xref py py-func docutils literal"><span class="pre">django.contrib.messages.add_message()</span></tt></a>, see that function&#8217;s
documentation for more details. One difference is that the level may be
passed as a string label in addition to integer/constant.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_paginator">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_paginator</tt>(<em>queryset</em>, <em>per_page</em>, <em>orphans=0</em>, <em>allow_empty_first_page=True</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_paginator" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an instance of the paginator to use for this view. By default,
instantiates an instance of <a class="reference internal" href="#django.contrib.admin.ModelAdmin.paginator" title="django.contrib.admin.ModelAdmin.paginator"><tt class="xref py py-attr docutils literal"><span class="pre">paginator</span></tt></a>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.response_add">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">response_add</tt>(<em>request</em>, <em>obj</em>, <em>post_url_continue=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.response_add" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines the <a class="reference internal" href="../../request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><tt class="xref py py-class docutils literal"><span class="pre">HttpResponse</span></tt></a> for the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.add_view" title="django.contrib.admin.ModelAdmin.add_view"><tt class="xref py py-meth docutils literal"><span class="pre">add_view()</span></tt></a> stage.</p>
<p><tt class="docutils literal"><span class="pre">response_add</span></tt> is called after the admin form is submitted and
just after the object and all the related instances have
been created and saved. You can override it to change the default behavior
after the object has been created.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.response_change">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">response_change</tt>(<em>request</em>, <em>obj</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.response_change" title="Permalink to this definition">¶</a></dt>
<dd><p>Determines the <a class="reference internal" href="../../request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><tt class="xref py py-class docutils literal"><span class="pre">HttpResponse</span></tt></a> for the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.change_view" title="django.contrib.admin.ModelAdmin.change_view"><tt class="xref py py-meth docutils literal"><span class="pre">change_view()</span></tt></a> stage.</p>
<p><tt class="docutils literal"><span class="pre">response_change</span></tt> is called after the admin form is submitted and
just after the object and all the related instances have
been saved. You can override it to change the default
behavior after the object has been changed.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.response_delete">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">response_delete</tt>(<em>request</em>, <em>obj_display</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.response_delete" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>Determines the <a class="reference internal" href="../../request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><tt class="xref py py-class docutils literal"><span class="pre">HttpResponse</span></tt></a> for the
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.delete_view" title="django.contrib.admin.ModelAdmin.delete_view"><tt class="xref py py-meth docutils literal"><span class="pre">delete_view()</span></tt></a> stage.</p>
<p><tt class="docutils literal"><span class="pre">response_delete</span></tt> is called after the object has been
deleted. You can override it to change the default
behavior after the object has been deleted.</p>
<p><tt class="docutils literal"><span class="pre">obj_display</span></tt> is a string with the name of the deleted
object.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.get_changeform_initial_data">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">get_changeform_initial_data</tt>(<em>request</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.get_changeform_initial_data" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>A hook for the initial data on admin change forms. By default, fields are
given initial values from <tt class="docutils literal"><span class="pre">GET</span></tt> parameters. For instance,
<tt class="docutils literal"><span class="pre">?name=initial_value</span></tt> will set the <tt class="docutils literal"><span class="pre">name</span></tt> field&#8217;s initial value to be
<tt class="docutils literal"><span class="pre">initial_value</span></tt>.</p>
<p>This method should return a dictionary in the form
<tt class="docutils literal"><span class="pre">{'fieldname':</span> <span class="pre">'fieldval'}</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_changeform_initial_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">{</span><span class="s">&#39;name&#39;</span><span class="p">:</span> <span class="s">&#39;custom_initial_value&#39;</span><span class="p">}</span>
</pre></div>
</div>
</dd></dl>

<div class="section" id="s-other-methods">
<span id="other-methods"></span><h4>Other methods<a class="headerlink" href="#other-methods" title="Permalink to this headline">¶</a></h4>
<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.add_view">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">add_view</tt>(<em>request</em>, <em>form_url=''</em>, <em>extra_context=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.add_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Django view for the model instance addition page. See note below.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.change_view">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">change_view</tt>(<em>request</em>, <em>object_id</em>, <em>form_url=''</em>, <em>extra_context=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.change_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Django view for the model instance edition page. See note below.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.changelist_view">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">changelist_view</tt>(<em>request</em>, <em>extra_context=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.changelist_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Django view for the model instances change list/actions page. See note
below.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.delete_view">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">delete_view</tt>(<em>request</em>, <em>object_id</em>, <em>extra_context=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.delete_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Django view for the model instance(s) deletion confirmation page. See note
below.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.ModelAdmin.history_view">
<tt class="descclassname">ModelAdmin.</tt><tt class="descname">history_view</tt>(<em>request</em>, <em>object_id</em>, <em>extra_context=None</em>)<a class="headerlink" href="#django.contrib.admin.ModelAdmin.history_view" title="Permalink to this definition">¶</a></dt>
<dd><p>Django view for the page that shows the modification history for a given
model instance.</p>
</dd></dl>

<p>Unlike the hook-type <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> methods detailed in the previous section,
these five methods are in reality designed to be invoked as Django views from
the admin application URL dispatching handler to render the pages that deal
with model instances CRUD operations. As a result, completely overriding these
methods will significantly change the behavior of the admin application.</p>
<p>One common reason for overriding these methods is to augment the context data
that is provided to the template that renders the view. In the following
example, the change view is overridden so that the rendered template is
provided some extra mapping data that would not otherwise be available:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyModelAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>

    <span class="c"># A template for a very customized change view:</span>
    <span class="n">change_form_template</span> <span class="o">=</span> <span class="s">&#39;admin/myapp/extras/openstreetmap_change_form.html&#39;</span>

    <span class="k">def</span> <span class="nf">get_osm_info</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># ...</span>
        <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">change_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">object_id</span><span class="p">,</span> <span class="n">form_url</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">extra_context</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="n">extra_context</span> <span class="o">=</span> <span class="n">extra_context</span> <span class="ow">or</span> <span class="p">{}</span>
        <span class="n">extra_context</span><span class="p">[</span><span class="s">&#39;osm_data&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_osm_info</span><span class="p">()</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">MyModelAdmin</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">change_view</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">object_id</span><span class="p">,</span>
            <span class="n">form_url</span><span class="p">,</span> <span class="n">extra_context</span><span class="o">=</span><span class="n">extra_context</span><span class="p">)</span>
</pre></div>
</div>
<p>These views return <a class="reference internal" href="../../template-response.html#django.template.response.TemplateResponse" title="django.template.response.TemplateResponse"><tt class="xref py py-class docutils literal"><span class="pre">TemplateResponse</span></tt></a>
instances which allow you to easily customize the response data before
rendering. For more details, see the <a class="reference internal" href="../../template-response.html"><em>TemplateResponse documentation</em></a>.</p>
</div>
</div>
<div class="section" id="s-modeladmin-asset-definitions">
<span id="s-id1"></span><span id="modeladmin-asset-definitions"></span><span id="id1"></span><h3><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> asset definitions<a class="headerlink" href="#modeladmin-asset-definitions" title="Permalink to this headline">¶</a></h3>
<p>There are times where you would like add a bit of CSS and/or JavaScript to
the add/change views. This can be accomplished by using a <tt class="docutils literal"><span class="pre">Media</span></tt> inner class
on your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">class</span> <span class="nc">Media</span><span class="p">:</span>
        <span class="n">css</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&quot;all&quot;</span><span class="p">:</span> <span class="p">(</span><span class="s">&quot;my_styles.css&quot;</span><span class="p">,)</span>
        <span class="p">}</span>
        <span class="n">js</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;my_code.js&quot;</span><span class="p">,)</span>
</pre></div>
</div>
<p>The <a class="reference internal" href="../staticfiles.html"><em>staticfiles app</em></a> prepends
<a class="reference internal" href="../../settings.html#std:setting-STATIC_URL"><tt class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></tt></a> (or <a class="reference internal" href="../../settings.html#std:setting-MEDIA_URL"><tt class="xref std std-setting docutils literal"><span class="pre">MEDIA_URL</span></tt></a> if <a class="reference internal" href="../../settings.html#std:setting-STATIC_URL"><tt class="xref std std-setting docutils literal"><span class="pre">STATIC_URL</span></tt></a> is
<tt class="docutils literal"><span class="pre">None</span></tt>) to any asset paths. The same rules apply as <a class="reference internal" href="../../../topics/forms/media.html#form-asset-paths"><em>regular asset
definitions on forms</em></a>.</p>
<div class="section" id="s-jquery">
<span id="jquery"></span><h4>jQuery<a class="headerlink" href="#jquery" title="Permalink to this headline">¶</a></h4>
<p>Django admin Javascript makes use of the <a class="reference external" href="http://jquery.com">jQuery</a> library.</p>
<p>To avoid conflicts with user-supplied scripts or libraries, Django&#8217;s jQuery
(version 1.9.1) is namespaced as <tt class="docutils literal"><span class="pre">django.jQuery</span></tt>. If you want to use jQuery
in your own admin JavaScript without including a second copy, you can use the
<tt class="docutils literal"><span class="pre">django.jQuery</span></tt> object on changelist and add/edit views.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> <p>The embedded jQuery has been upgraded from 1.4.2 to 1.9.1.</p>
</div>
<p>The <a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a> class requires jQuery by default, so there is no need
to add jQuery to your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>’s list of media resources unless you have
a specific need. For example, if you require the jQuery library to be in the
global namespace (for example when using third-party jQuery plugins) or if you
need a newer version of jQuery, you will have to include your own copy.</p>
<p>Django provides both uncompressed and &#8216;minified&#8217; versions of jQuery, as
<tt class="docutils literal"><span class="pre">jquery.js</span></tt> and <tt class="docutils literal"><span class="pre">jquery.min.js</span></tt> respectively.</p>
<p><a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a> and <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin" title="django.contrib.admin.InlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">InlineModelAdmin</span></tt></a> have a <tt class="docutils literal"><span class="pre">media</span></tt> property
that returns a list of <tt class="docutils literal"><span class="pre">Media</span></tt> objects which store paths to the JavaScript
files for the forms and/or formsets. If <a class="reference internal" href="../../settings.html#std:setting-DEBUG"><tt class="xref std std-setting docutils literal"><span class="pre">DEBUG</span></tt></a> is <tt class="docutils literal"><span class="pre">True</span></tt> it will
return the uncompressed versions of the various JavaScript files, including
<tt class="docutils literal"><span class="pre">jquery.js</span></tt>; if not, it will return the &#8216;minified&#8217; versions.</p>
</div>
</div>
<div class="section" id="s-adding-custom-validation-to-the-admin">
<span id="s-admin-custom-validation"></span><span id="adding-custom-validation-to-the-admin"></span><span id="admin-custom-validation"></span><h3>Adding custom validation to the admin<a class="headerlink" href="#adding-custom-validation-to-the-admin" title="Permalink to this headline">¶</a></h3>
<p>Adding custom validation of data in the admin is quite easy. The automatic
admin interface reuses <a class="reference internal" href="../../forms/api.html#module-django.forms" title="django.forms"><tt class="xref py py-mod docutils literal"><span class="pre">django.forms</span></tt></a>, and the <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> class gives
you the ability define your own form:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">ArticleAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">form</span> <span class="o">=</span> <span class="n">MyArticleAdminForm</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">MyArticleAdminForm</span></tt> can be defined anywhere as long as you import where
needed. Now within your form you can add your own custom validation for
any field:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyArticleAdminForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">ModelForm</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">clean_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># do something that validates your data</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cleaned_data</span><span class="p">[</span><span class="s">&quot;name&quot;</span><span class="p">]</span>
</pre></div>
</div>
<p>It is important you use a <tt class="docutils literal"><span class="pre">ModelForm</span></tt> here otherwise things can break. See
the <a class="reference internal" href="../../forms/index.html"><em>forms</em></a> documentation on <a class="reference internal" href="../../forms/validation.html"><em>custom validation</em></a> and, more specifically, the
<a class="reference internal" href="../../../topics/forms/modelforms.html#overriding-modelform-clean-method"><em>model form validation notes</em></a> for more
information.</p>
</div>
</div>
<div class="section" id="s-inlinemodeladmin-objects">
<span id="s-admin-inlines"></span><span id="inlinemodeladmin-objects"></span><span id="admin-inlines"></span><h2><tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> objects<a class="headerlink" href="#inlinemodeladmin-objects" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.admin.InlineModelAdmin">
<em class="property">class </em><tt class="descname">InlineModelAdmin</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="django.contrib.admin.TabularInline">
<em class="property">class </em><tt class="descname">TabularInline</tt><a class="headerlink" href="#django.contrib.admin.TabularInline" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="class">
<dt id="django.contrib.admin.StackedInline">
<em class="property">class </em><tt class="descname">StackedInline</tt><a class="headerlink" href="#django.contrib.admin.StackedInline" title="Permalink to this definition">¶</a></dt>
<dd><p>The admin interface has the ability to edit models on the same page as a
parent model. These are called inlines. Suppose you have these two models:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Author</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Book</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
   <span class="n">author</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Author</span><span class="p">)</span>
   <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
</pre></div>
</div>
<p>You can edit the books authored by an author on the author page. You add
inlines to a model by specifying them in a <tt class="docutils literal"><span class="pre">ModelAdmin.inlines</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">BookInline</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Book</span>

<span class="k">class</span> <span class="nc">AuthorAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">BookInline</span><span class="p">,</span>
    <span class="p">]</span>
</pre></div>
</div>
<p>Django provides two subclasses of <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> and they are:</p>
<ul class="simple">
<li><a class="reference internal" href="#django.contrib.admin.TabularInline" title="django.contrib.admin.TabularInline"><tt class="xref py py-class docutils literal"><span class="pre">TabularInline</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.StackedInline" title="django.contrib.admin.StackedInline"><tt class="xref py py-class docutils literal"><span class="pre">StackedInline</span></tt></a></li>
</ul>
<p>The difference between these two is merely the template used to render
them.</p>
</dd></dl>

<div class="section" id="s-inlinemodeladmin-options">
<span id="inlinemodeladmin-options"></span><h3><tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> options<a class="headerlink" href="#inlinemodeladmin-options" title="Permalink to this headline">¶</a></h3>
<p><tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> shares many of the same features as <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>, and
adds some of its own (the shared features are actually defined in the
<tt class="docutils literal"><span class="pre">BaseModelAdmin</span></tt> superclass). The shared features are:</p>
<ul class="simple">
<li><a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.form" title="django.contrib.admin.InlineModelAdmin.form"><tt class="xref py py-attr docutils literal"><span class="pre">form</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.fieldsets" title="django.contrib.admin.ModelAdmin.fieldsets"><tt class="xref py py-attr docutils literal"><span class="pre">fieldsets</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.fields" title="django.contrib.admin.ModelAdmin.fields"><tt class="xref py py-attr docutils literal"><span class="pre">fields</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.formfield_overrides" title="django.contrib.admin.ModelAdmin.formfield_overrides"><tt class="xref py py-attr docutils literal"><span class="pre">formfield_overrides</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.exclude" title="django.contrib.admin.ModelAdmin.exclude"><tt class="xref py py-attr docutils literal"><span class="pre">exclude</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.filter_horizontal" title="django.contrib.admin.ModelAdmin.filter_horizontal"><tt class="xref py py-attr docutils literal"><span class="pre">filter_horizontal</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.filter_vertical" title="django.contrib.admin.ModelAdmin.filter_vertical"><tt class="xref py py-attr docutils literal"><span class="pre">filter_vertical</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.ordering" title="django.contrib.admin.ModelAdmin.ordering"><tt class="xref py py-attr docutils literal"><span class="pre">ordering</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.prepopulated_fields" title="django.contrib.admin.ModelAdmin.prepopulated_fields"><tt class="xref py py-attr docutils literal"><span class="pre">prepopulated_fields</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_queryset" title="django.contrib.admin.ModelAdmin.get_queryset"><tt class="xref py py-meth docutils literal"><span class="pre">get_queryset()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.radio_fields" title="django.contrib.admin.ModelAdmin.radio_fields"><tt class="xref py py-attr docutils literal"><span class="pre">radio_fields</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.readonly_fields" title="django.contrib.admin.ModelAdmin.readonly_fields"><tt class="xref py py-attr docutils literal"><span class="pre">readonly_fields</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.raw_id_fields" title="django.contrib.admin.InlineModelAdmin.raw_id_fields"><tt class="xref py py-attr docutils literal"><span class="pre">raw_id_fields</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.formfield_for_choice_field" title="django.contrib.admin.ModelAdmin.formfield_for_choice_field"><tt class="xref py py-meth docutils literal"><span class="pre">formfield_for_choice_field()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.formfield_for_foreignkey" title="django.contrib.admin.ModelAdmin.formfield_for_foreignkey"><tt class="xref py py-meth docutils literal"><span class="pre">formfield_for_foreignkey()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.formfield_for_manytomany" title="django.contrib.admin.ModelAdmin.formfield_for_manytomany"><tt class="xref py py-meth docutils literal"><span class="pre">formfield_for_manytomany()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.has_add_permission" title="django.contrib.admin.ModelAdmin.has_add_permission"><tt class="xref py py-meth docutils literal"><span class="pre">has_add_permission()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.has_change_permission" title="django.contrib.admin.ModelAdmin.has_change_permission"><tt class="xref py py-meth docutils literal"><span class="pre">has_change_permission()</span></tt></a></li>
<li><a class="reference internal" href="#django.contrib.admin.ModelAdmin.has_delete_permission" title="django.contrib.admin.ModelAdmin.has_delete_permission"><tt class="xref py py-meth docutils literal"><span class="pre">has_delete_permission()</span></tt></a></li>
</ul>
<p>The <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> class adds:</p>
<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.model">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">model</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.model" title="Permalink to this definition">¶</a></dt>
<dd><p>The model which the inline is using. This is required.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.fk_name">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">fk_name</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.fk_name" title="Permalink to this definition">¶</a></dt>
<dd><p>The name of the foreign key on the model. In most cases this will be dealt
with automatically, but <tt class="docutils literal"><span class="pre">fk_name</span></tt> must be specified explicitly if there
are more than one foreign key to the same parent model.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.formset">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">formset</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.formset" title="Permalink to this definition">¶</a></dt>
<dd><p>This defaults to <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.models.BaseInlineFormSet" title="django.forms.models.BaseInlineFormSet"><tt class="xref py py-class docutils literal"><span class="pre">BaseInlineFormSet</span></tt></a>. Using
your own formset can give you many possibilities of customization. Inlines
are built around <a class="reference internal" href="../../../topics/forms/modelforms.html#model-formsets"><em>model formsets</em></a>.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.form">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">form</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.form" title="Permalink to this definition">¶</a></dt>
<dd><p>The value for <tt class="docutils literal"><span class="pre">form</span></tt> defaults to <tt class="docutils literal"><span class="pre">ModelForm</span></tt>. This is what is passed
through to <a class="reference internal" href="../../forms/models.html#django.forms.models.inlineformset_factory" title="django.forms.models.inlineformset_factory"><tt class="xref py py-func docutils literal"><span class="pre">inlineformset_factory()</span></tt></a> when
creating the formset for this inline.</p>
</dd></dl>

<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">When writing custom validation for <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> forms, be cautious
of writing validation that relies on features of the parent model. If the
parent model fails to validate, it may be left in an inconsistent state as
described in the warning in <a class="reference internal" href="../../../topics/forms/modelforms.html#validation-on-modelform"><em>Validation on a ModelForm</em></a>.</p>
</div>
<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.extra">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">extra</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.extra" title="Permalink to this definition">¶</a></dt>
<dd><p>This controls the number of extra forms the formset will display in
addition to the initial forms. See the
<a class="reference internal" href="../../../topics/forms/formsets.html"><em>formsets documentation</em></a> for more
information.</p>
<p>For users with JavaScript-enabled browsers, an &#8220;Add another&#8221; link is
provided to enable any number of additional inlines to be added in addition
to those provided as a result of the <tt class="docutils literal"><span class="pre">extra</span></tt> argument.</p>
<p>The dynamic link will not appear if the number of currently displayed forms
exceeds <tt class="docutils literal"><span class="pre">max_num</span></tt>, or if the user does not have JavaScript enabled.</p>
<div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p><a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.get_extra" title="django.contrib.admin.InlineModelAdmin.get_extra"><tt class="xref py py-meth docutils literal"><span class="pre">InlineModelAdmin.get_extra()</span></tt></a> also allows you to customize the number
of extra forms.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.max_num">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">max_num</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.max_num" title="Permalink to this definition">¶</a></dt>
<dd><p>This controls the maximum number of forms to show in the inline. This
doesn&#8217;t directly correlate to the number of objects, but can if the value
is small enough. See <a class="reference internal" href="../../../topics/forms/modelforms.html#model-formsets-max-num"><em>Limiting the number of editable objects</em></a> for more information.</p>
<div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p><a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.get_max_num" title="django.contrib.admin.InlineModelAdmin.get_max_num"><tt class="xref py py-meth docutils literal"><span class="pre">InlineModelAdmin.get_max_num()</span></tt></a> also allows you to customize the
maximum number of extra forms.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.min_num">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">min_num</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.min_num" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>This controls the minimum number of forms to show in the inline.
See <a class="reference internal" href="../../forms/models.html#django.forms.models.modelformset_factory" title="django.forms.models.modelformset_factory"><tt class="xref py py-func docutils literal"><span class="pre">modelformset_factory()</span></tt></a> for more information.</p>
<p><a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.get_min_num" title="django.contrib.admin.InlineModelAdmin.get_min_num"><tt class="xref py py-meth docutils literal"><span class="pre">InlineModelAdmin.get_min_num()</span></tt></a> also allows you to customize the
minimum number of displayed forms.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.raw_id_fields">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">raw_id_fields</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.raw_id_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>By default, Django&#8217;s admin uses a select-box interface (&lt;select&gt;) for
fields that are <tt class="docutils literal"><span class="pre">ForeignKey</span></tt>. Sometimes you don&#8217;t want to incur the
overhead of having to select all the related instances to display in the
drop-down.</p>
<p><tt class="docutils literal"><span class="pre">raw_id_fields</span></tt> is a list of fields you would like to change into a
<tt class="docutils literal"><span class="pre">Input</span></tt> widget for either a <tt class="docutils literal"><span class="pre">ForeignKey</span></tt> or <tt class="docutils literal"><span class="pre">ManyToManyField</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">BookInline</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Book</span>
    <span class="n">raw_id_fields</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;pages&quot;</span><span class="p">,)</span>
</pre></div>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.template">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">template</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.template" title="Permalink to this definition">¶</a></dt>
<dd><p>The template used to render the inline on the page.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.verbose_name">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">verbose_name</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.verbose_name" title="Permalink to this definition">¶</a></dt>
<dd><p>An override to the <tt class="docutils literal"><span class="pre">verbose_name</span></tt> found in the model&#8217;s inner <tt class="docutils literal"><span class="pre">Meta</span></tt>
class.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.verbose_name_plural">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">verbose_name_plural</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.verbose_name_plural" title="Permalink to this definition">¶</a></dt>
<dd><p>An override to the <tt class="docutils literal"><span class="pre">verbose_name_plural</span></tt> found in the model&#8217;s inner
<tt class="docutils literal"><span class="pre">Meta</span></tt> class.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.InlineModelAdmin.can_delete">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">can_delete</tt><a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.can_delete" title="Permalink to this definition">¶</a></dt>
<dd><p>Specifies whether or not inline objects can be deleted in the inline.
Defaults to <tt class="docutils literal"><span class="pre">True</span></tt>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.InlineModelAdmin.get_formset">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">get_formset</tt>(<em>request</em>, <em>obj=None</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.get_formset" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="../../../topics/forms/modelforms.html#django.forms.models.BaseInlineFormSet" title="django.forms.models.BaseInlineFormSet"><tt class="xref py py-class docutils literal"><span class="pre">BaseInlineFormSet</span></tt></a> class for use in
admin add/change views. See the example for
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_formsets_with_inlines" title="django.contrib.admin.ModelAdmin.get_formsets_with_inlines"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin.get_formsets_with_inlines</span></tt></a>.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.InlineModelAdmin.get_extra">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">get_extra</tt>(<em>request</em>, <em>obj=None</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.get_extra" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>Returns the number of extra inline forms to use. By default, returns the
<a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.extra" title="django.contrib.admin.InlineModelAdmin.extra"><tt class="xref py py-attr docutils literal"><span class="pre">InlineModelAdmin.extra</span></tt></a> attribute.</p>
<p>Override this method to programmatically determine the number of extra
inline forms. For example, this may be based on the model instance
(passed as the keyword argument <tt class="docutils literal"><span class="pre">obj</span></tt>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">BinaryTreeAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">BinaryTree</span>

    <span class="k">def</span> <span class="nf">get_extra</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">extra</span> <span class="o">=</span> <span class="mi">2</span>
        <span class="k">if</span> <span class="n">obj</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">extra</span> <span class="o">-</span> <span class="n">obj</span><span class="o">.</span><span class="n">binarytree_set</span><span class="o">.</span><span class="n">count</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">extra</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.InlineModelAdmin.get_max_num">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">get_max_num</tt>(<em>request</em>, <em>obj=None</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.get_max_num" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.6.</span> </div>
<p>Returns the maximum number of extra inline forms to use. By default,
returns the <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.max_num" title="django.contrib.admin.InlineModelAdmin.max_num"><tt class="xref py py-attr docutils literal"><span class="pre">InlineModelAdmin.max_num</span></tt></a> attribute.</p>
<p>Override this method to programmatically determine the maximum number of
inline forms. For example, this may be based on the model instance
(passed as the keyword argument <tt class="docutils literal"><span class="pre">obj</span></tt>):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">BinaryTreeAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">BinaryTree</span>

    <span class="k">def</span> <span class="nf">get_max_num</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">max_num</span> <span class="o">=</span> <span class="mi">10</span>
        <span class="k">if</span> <span class="n">obj</span><span class="o">.</span><span class="n">parent</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">max_num</span> <span class="o">-</span> <span class="mi">5</span>
        <span class="k">return</span> <span class="n">max_num</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.admin.InlineModelAdmin.get_min_num">
<tt class="descclassname">InlineModelAdmin.</tt><tt class="descname">get_min_num</tt>(<em>request</em>, <em>obj=None</em>, <em>**kwargs</em>)<a class="headerlink" href="#django.contrib.admin.InlineModelAdmin.get_min_num" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>Returns the minimum number of inline forms to use. By default,
returns the <a class="reference internal" href="#django.contrib.admin.InlineModelAdmin.min_num" title="django.contrib.admin.InlineModelAdmin.min_num"><tt class="xref py py-attr docutils literal"><span class="pre">InlineModelAdmin.min_num</span></tt></a> attribute.</p>
<p>Override this method to programmatically determine the minimum number of
inline forms. For example, this may be based on the model instance
(passed as the keyword argument <tt class="docutils literal"><span class="pre">obj</span></tt>).</p>
</dd></dl>

</div>
<div class="section" id="s-working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-model">
<span id="working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-model"></span><h3>Working with a model with two or more foreign keys to the same parent model<a class="headerlink" href="#working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-model" title="Permalink to this headline">¶</a></h3>
<p>It is sometimes possible to have more than one foreign key to the same model.
Take this model for instance:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Friendship</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">to_person</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">related_name</span><span class="o">=</span><span class="s">&quot;friends&quot;</span><span class="p">)</span>
    <span class="n">from_person</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">related_name</span><span class="o">=</span><span class="s">&quot;from_friends&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>If you wanted to display an inline on the <tt class="docutils literal"><span class="pre">Person</span></tt> admin add/change pages
you need to explicitly define the foreign key since it is unable to do so
automatically:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">myapp.models</span> <span class="kn">import</span> <span class="n">Friendship</span>

<span class="k">class</span> <span class="nc">FriendshipInline</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Friendship</span>
    <span class="n">fk_name</span> <span class="o">=</span> <span class="s">&quot;to_person&quot;</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">FriendshipInline</span><span class="p">,</span>
    <span class="p">]</span>
</pre></div>
</div>
</div>
<div class="section" id="s-working-with-many-to-many-models">
<span id="working-with-many-to-many-models"></span><h3>Working with many-to-many models<a class="headerlink" href="#working-with-many-to-many-models" title="Permalink to this headline">¶</a></h3>
<p>By default, admin widgets for many-to-many relations will be displayed
on whichever model contains the actual reference to the
<a class="reference internal" href="../../models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><tt class="xref py py-class docutils literal"><span class="pre">ManyToManyField</span></tt></a>. Depending on your <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>
definition, each many-to-many field in your model will be represented by a
standard HTML <tt class="docutils literal"><span class="pre">&lt;select</span> <span class="pre">multiple&gt;</span></tt>, a horizontal or vertical filter, or a
<tt class="docutils literal"><span class="pre">raw_id_admin</span></tt> widget. However, it is also possible to replace these
widgets with inlines.</p>
<p>Suppose we have the following models:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Group</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>
    <span class="n">members</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ManyToManyField</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">related_name</span><span class="o">=</span><span class="s">&#39;groups&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If you want to display many-to-many relations using an inline, you can do
so by defining an <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> object for the relationship:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="k">class</span> <span class="nc">MembershipInline</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Group</span><span class="o">.</span><span class="n">members</span><span class="o">.</span><span class="n">through</span>

<span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">MembershipInline</span><span class="p">,</span>
    <span class="p">]</span>

<span class="k">class</span> <span class="nc">GroupAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">MembershipInline</span><span class="p">,</span>
    <span class="p">]</span>
    <span class="n">exclude</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;members&#39;</span><span class="p">,)</span>
</pre></div>
</div>
<p>There are two features worth noting in this example.</p>
<p>Firstly - the <tt class="docutils literal"><span class="pre">MembershipInline</span></tt> class references <tt class="docutils literal"><span class="pre">Group.members.through</span></tt>.
The <tt class="docutils literal"><span class="pre">through</span></tt> attribute is a reference to the model that manages the
many-to-many relation. This model is automatically created by Django when you
define a many-to-many field.</p>
<p>Secondly, the <tt class="docutils literal"><span class="pre">GroupAdmin</span></tt> must manually exclude the <tt class="docutils literal"><span class="pre">members</span></tt> field.
Django displays an admin widget for a many-to-many field on the model that
defines the relation (in this case, <tt class="docutils literal"><span class="pre">Group</span></tt>). If you want to use an inline
model to represent the many-to-many relationship, you must tell Django&#8217;s admin
to <em>not</em> display this widget - otherwise you will end up with two widgets on
your admin page for managing the relation.</p>
<p>In all other respects, the <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> is exactly the same as any
other. You can customize the appearance using any of the normal
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> properties.</p>
</div>
<div class="section" id="s-working-with-many-to-many-intermediary-models">
<span id="working-with-many-to-many-intermediary-models"></span><h3>Working with many-to-many intermediary models<a class="headerlink" href="#working-with-many-to-many-intermediary-models" title="Permalink to this headline">¶</a></h3>
<p>When you specify an intermediary model using the <tt class="docutils literal"><span class="pre">through</span></tt> argument to a
<a class="reference internal" href="../../models/fields.html#django.db.models.ManyToManyField" title="django.db.models.ManyToManyField"><tt class="xref py py-class docutils literal"><span class="pre">ManyToManyField</span></tt></a>, the admin will not display a
widget by default. This is because each instance of that intermediary model
requires more information than could be displayed in a single widget, and the
layout required for multiple widgets will vary depending on the intermediate
model.</p>
<p>However, we still want to be able to edit that information inline. Fortunately,
this is easy to do with inline admin models. Suppose we have the following
models:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>

<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Group</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>
    <span class="n">members</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ManyToManyField</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">through</span><span class="o">=</span><span class="s">&#39;Membership&#39;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Membership</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">person</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Person</span><span class="p">)</span>
    <span class="n">group</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Group</span><span class="p">)</span>
    <span class="n">date_joined</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">()</span>
    <span class="n">invite_reason</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span>
</pre></div>
</div>
<p>The first step in displaying this intermediate model in the admin is to
define an inline class for the <tt class="docutils literal"><span class="pre">Membership</span></tt> model:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MembershipInline</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">TabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Membership</span>
    <span class="n">extra</span> <span class="o">=</span> <span class="mi">1</span>
</pre></div>
</div>
<p>This simple example uses the default <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> values for the
<tt class="docutils literal"><span class="pre">Membership</span></tt> model, and limits the extra add forms to one. This could be
customized using any of the options available to <tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> classes.</p>
<p>Now create admin views for the <tt class="docutils literal"><span class="pre">Person</span></tt> and <tt class="docutils literal"><span class="pre">Group</span></tt> models:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">PersonAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">(</span><span class="n">MembershipInline</span><span class="p">,)</span>

<span class="k">class</span> <span class="nc">GroupAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">(</span><span class="n">MembershipInline</span><span class="p">,)</span>
</pre></div>
</div>
<p>Finally, register your <tt class="docutils literal"><span class="pre">Person</span></tt> and <tt class="docutils literal"><span class="pre">Group</span></tt> models with the admin site:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Person</span><span class="p">,</span> <span class="n">PersonAdmin</span><span class="p">)</span>
<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Group</span><span class="p">,</span> <span class="n">GroupAdmin</span><span class="p">)</span>
</pre></div>
</div>
<p>Now your admin site is set up to edit <tt class="docutils literal"><span class="pre">Membership</span></tt> objects inline from
either the <tt class="docutils literal"><span class="pre">Person</span></tt> or the <tt class="docutils literal"><span class="pre">Group</span></tt> detail pages.</p>
</div>
<div class="section" id="s-using-generic-relations-as-an-inline">
<span id="s-id3"></span><span id="using-generic-relations-as-an-inline"></span><span id="id3"></span><h3>Using generic relations as an inline<a class="headerlink" href="#using-generic-relations-as-an-inline" title="Permalink to this headline">¶</a></h3>
<p>It is possible to use an inline with generically related objects. Let&#8217;s say
you have the following models:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.contrib.contenttypes.fields</span> <span class="kn">import</span> <span class="n">GenericForeignKey</span>

<span class="k">class</span> <span class="nc">Image</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">image</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ImageField</span><span class="p">(</span><span class="n">upload_to</span><span class="o">=</span><span class="s">&quot;images&quot;</span><span class="p">)</span>
    <span class="n">content_type</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">ContentType</span><span class="p">)</span>
    <span class="n">object_id</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">PositiveIntegerField</span><span class="p">()</span>
    <span class="n">content_object</span> <span class="o">=</span> <span class="n">GenericForeignKey</span><span class="p">(</span><span class="s">&quot;content_type&quot;</span><span class="p">,</span> <span class="s">&quot;object_id&quot;</span><span class="p">)</span>

<span class="k">class</span> <span class="nc">Product</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
</pre></div>
</div>
<p>If you want to allow editing and creating <tt class="docutils literal"><span class="pre">Image</span></tt> instance on the <tt class="docutils literal"><span class="pre">Product</span></tt>
add/change views you can use <a class="reference internal" href="../contenttypes.html#django.contrib.contenttypes.admin.GenericTabularInline" title="django.contrib.contenttypes.admin.GenericTabularInline"><tt class="xref py py-class docutils literal"><span class="pre">GenericTabularInline</span></tt></a>
or <a class="reference internal" href="../contenttypes.html#django.contrib.contenttypes.admin.GenericStackedInline" title="django.contrib.contenttypes.admin.GenericStackedInline"><tt class="xref py py-class docutils literal"><span class="pre">GenericStackedInline</span></tt></a> (both
subclasses of <a class="reference internal" href="../contenttypes.html#django.contrib.contenttypes.admin.GenericInlineModelAdmin" title="django.contrib.contenttypes.admin.GenericInlineModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">GenericInlineModelAdmin</span></tt></a>)
provided by <a class="reference internal" href="../contenttypes.html#module-django.contrib.contenttypes.admin" title="django.contrib.contenttypes.admin"><tt class="xref py py-mod docutils literal"><span class="pre">admin</span></tt></a>, they implement tabular and
stacked visual layouts for the forms representing the inline objects
respectively just like their non-generic counterparts and behave just like any
other inline. In your <tt class="docutils literal"><span class="pre">admin.py</span></tt> for this example app:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
<span class="kn">from</span> <span class="nn">django.contrib.contenttypes.admin</span> <span class="kn">import</span> <span class="n">GenericTabularInline</span>

<span class="kn">from</span> <span class="nn">myproject.myapp.models</span> <span class="kn">import</span> <span class="n">Image</span><span class="p">,</span> <span class="n">Product</span>

<span class="k">class</span> <span class="nc">ImageInline</span><span class="p">(</span><span class="n">GenericTabularInline</span><span class="p">):</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">Image</span>

<span class="k">class</span> <span class="nc">ProductAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="n">inlines</span> <span class="o">=</span> <span class="p">[</span>
        <span class="n">ImageInline</span><span class="p">,</span>
    <span class="p">]</span>

<span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">Product</span><span class="p">,</span> <span class="n">ProductAdmin</span><span class="p">)</span>
</pre></div>
</div>
<p>See the <a class="reference internal" href="../contenttypes.html"><em>contenttypes documentation</em></a> for more
specific information.</p>
</div>
</div>
<div class="section" id="s-overriding-admin-templates">
<span id="s-admin-overriding-templates"></span><span id="overriding-admin-templates"></span><span id="admin-overriding-templates"></span><h2>Overriding admin templates<a class="headerlink" href="#overriding-admin-templates" title="Permalink to this headline">¶</a></h2>
<p>It is relatively easy to override many of the templates which the admin module
uses to generate the various pages of an admin site. You can even override a
few of these templates for a specific app, or a specific model.</p>
<div class="section" id="s-set-up-your-projects-admin-template-directories">
<span id="set-up-your-projects-admin-template-directories"></span><h3>Set up your projects admin template directories<a class="headerlink" href="#set-up-your-projects-admin-template-directories" title="Permalink to this headline">¶</a></h3>
<p>The admin template files are located in the <tt class="docutils literal"><span class="pre">contrib/admin/templates/admin</span></tt>
directory.</p>
<p>In order to override one or more of them, first create an <tt class="docutils literal"><span class="pre">admin</span></tt> directory
in your project&#8217;s <tt class="docutils literal"><span class="pre">templates</span></tt> directory. This can be any of the directories
you specified in <a class="reference internal" href="../../settings.html#std:setting-TEMPLATE_DIRS"><tt class="xref std std-setting docutils literal"><span class="pre">TEMPLATE_DIRS</span></tt></a>. If you have customized the
<a class="reference internal" href="../../settings.html#std:setting-TEMPLATE_LOADERS"><tt class="xref std std-setting docutils literal"><span class="pre">TEMPLATE_LOADERS</span></tt></a> setting, be sure
<tt class="docutils literal"><span class="pre">'django.template.loaders.filesystem.Loader'</span></tt> appears before
<tt class="docutils literal"><span class="pre">'django.template.loaders.app_directories.Loader'</span></tt> so that your custom
templates will be found by the template loading system before those that are
included with <a class="reference internal" href="#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><tt class="xref py py-mod docutils literal"><span class="pre">django.contrib.admin</span></tt></a>.</p>
<p>Within this <tt class="docutils literal"><span class="pre">admin</span></tt> directory, create sub-directories named after your app.
Within these app subdirectories create sub-directories named after your models.
Note, that the admin app will lowercase the model name when looking for the
directory, so make sure you name the directory in all lowercase if you are
going to run your app on a case-sensitive filesystem.</p>
<p>To override an admin template for a specific app, copy and edit the template
from the <tt class="docutils literal"><span class="pre">django/contrib/admin/templates/admin</span></tt> directory, and save it to one
of the directories you just created.</p>
<p>For example, if we wanted to add a tool to the change list view for all the
models in an app named <tt class="docutils literal"><span class="pre">my_app</span></tt>, we would copy
<tt class="docutils literal"><span class="pre">contrib/admin/templates/admin/change_list.html</span></tt> to the
<tt class="docutils literal"><span class="pre">templates/admin/my_app/</span></tt> directory of our project, and make any necessary
changes.</p>
<p>If we wanted to add a tool to the change list view for only a specific model
named &#8216;Page&#8217;, we would copy that same file to the
<tt class="docutils literal"><span class="pre">templates/admin/my_app/page</span></tt> directory of our project.</p>
</div>
<div class="section" id="s-overriding-vs-replacing-an-admin-template">
<span id="overriding-vs-replacing-an-admin-template"></span><h3>Overriding vs. replacing an admin template<a class="headerlink" href="#overriding-vs-replacing-an-admin-template" title="Permalink to this headline">¶</a></h3>
<p>Because of the modular design of the admin templates, it is usually neither
necessary nor advisable to replace an entire template. It is almost always
better to override only the section of the template which you need to change.</p>
<p>To continue the example above, we want to add a new link next to the
<tt class="docutils literal"><span class="pre">History</span></tt> tool for the <tt class="docutils literal"><span class="pre">Page</span></tt> model. After looking at <tt class="docutils literal"><span class="pre">change_form.html</span></tt>
we determine that we only need to override the <tt class="docutils literal"><span class="pre">object-tools-items</span></tt> block.
Therefore here is our new <tt class="docutils literal"><span class="pre">change_form.html</span></tt> :</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;admin/change_form.html&quot;</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">load</span> <span class="nv">i18n</span> <span class="nv">admin_urls</span> <span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">block</span> <span class="nv">object-tools-items</span> <span class="cp">%}</span>
    <span class="nt">&lt;li&gt;</span>
        <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">url</span> <span class="nv">opts</span><span class="o">|</span><span class="nf">admin_urlname</span><span class="s1">:&#39;history&#39;</span> <span class="nv">original.pk</span><span class="o">|</span><span class="nf">admin_urlquote</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">class=</span><span class="s">&quot;historylink&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">trans</span> <span class="s2">&quot;History&quot;</span> <span class="cp">%}</span><span class="nt">&lt;/a&gt;</span>
    <span class="nt">&lt;/li&gt;</span>
    <span class="nt">&lt;li&gt;</span>
        <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;mylink/&quot;</span> <span class="na">class=</span><span class="s">&quot;historylink&quot;</span><span class="nt">&gt;</span>My Link<span class="nt">&lt;/a&gt;</span>
    <span class="nt">&lt;/li&gt;</span>
    <span class="cp">{%</span> <span class="k">if</span> <span class="nv">has_absolute_url</span> <span class="cp">%}</span>
        <span class="nt">&lt;li&gt;</span>
            <span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">url</span> <span class="s1">&#39;admin:view_on_site&#39;</span> <span class="nv">content_type_id</span> <span class="nv">original.pk</span> <span class="cp">%}</span><span class="s">&quot;</span> <span class="na">class=</span><span class="s">&quot;viewsitelink&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">trans</span> <span class="s2">&quot;View on site&quot;</span> <span class="cp">%}</span><span class="nt">&lt;/a&gt;</span>
        <span class="nt">&lt;/li&gt;</span>
    <span class="cp">{%</span> <span class="k">endif</span><span class="cp">%}</span>
<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>And that&#8217;s it! If we placed this file in the <tt class="docutils literal"><span class="pre">templates/admin/my_app</span></tt>
directory, our link would appear on the change form for all models within
my_app.</p>
</div>
<div class="section" id="s-templates-which-may-be-overridden-per-app-or-model">
<span id="templates-which-may-be-overridden-per-app-or-model"></span><h3>Templates which may be overridden per app or model<a class="headerlink" href="#templates-which-may-be-overridden-per-app-or-model" title="Permalink to this headline">¶</a></h3>
<p>Not every template in <tt class="docutils literal"><span class="pre">contrib/admin/templates/admin</span></tt> may be overridden per
app or per model. The following can:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">app_index.html</span></tt></li>
<li><tt class="docutils literal"><span class="pre">change_form.html</span></tt></li>
<li><tt class="docutils literal"><span class="pre">change_list.html</span></tt></li>
<li><tt class="docutils literal"><span class="pre">delete_confirmation.html</span></tt></li>
<li><tt class="docutils literal"><span class="pre">object_history.html</span></tt></li>
</ul>
<p>For those templates that cannot be overridden in this way, you may still
override them for your entire project. Just place the new version in your
<tt class="docutils literal"><span class="pre">templates/admin</span></tt> directory. This is particularly useful to create custom 404
and 500 pages.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some of the admin templates, such as <tt class="docutils literal"><span class="pre">change_list_results.html</span></tt> are used
to render custom inclusion tags. These may be overridden, but in such cases
you are probably better off creating your own version of the tag in
question and giving it a different name. That way you can use it
selectively.</p>
</div>
</div>
<div class="section" id="s-root-and-login-templates">
<span id="root-and-login-templates"></span><h3>Root and login templates<a class="headerlink" href="#root-and-login-templates" title="Permalink to this headline">¶</a></h3>
<p>If you wish to change the index, login or logout templates, you are better off
creating your own <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instance (see below), and changing the
<a class="reference internal" href="#django.contrib.admin.AdminSite.index_template" title="django.contrib.admin.AdminSite.index_template"><tt class="xref py py-attr docutils literal"><span class="pre">AdminSite.index_template</span></tt></a> , <a class="reference internal" href="#django.contrib.admin.AdminSite.login_template" title="django.contrib.admin.AdminSite.login_template"><tt class="xref py py-attr docutils literal"><span class="pre">AdminSite.login_template</span></tt></a> or
<a class="reference internal" href="#django.contrib.admin.AdminSite.logout_template" title="django.contrib.admin.AdminSite.logout_template"><tt class="xref py py-attr docutils literal"><span class="pre">AdminSite.logout_template</span></tt></a> properties.</p>
</div>
</div>
<div class="section" id="s-adminsite-objects">
<span id="adminsite-objects"></span><h2><tt class="docutils literal"><span class="pre">AdminSite</span></tt> objects<a class="headerlink" href="#adminsite-objects" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.admin.AdminSite">
<em class="property">class </em><tt class="descname">AdminSite</tt>(<em>name='admin'</em>)<a class="headerlink" href="#django.contrib.admin.AdminSite" title="Permalink to this definition">¶</a></dt>
<dd><p>A Django administrative site is represented by an instance of
<tt class="docutils literal"><span class="pre">django.contrib.admin.sites.AdminSite</span></tt>; by default, an instance of
this class is created as <tt class="docutils literal"><span class="pre">django.contrib.admin.site</span></tt> and you can
register your models and <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> instances with it.</p>
<p>When constructing an instance of an <tt class="docutils literal"><span class="pre">AdminSite</span></tt>, you can provide
a unique instance name using the <tt class="docutils literal"><span class="pre">name</span></tt> argument to the constructor. This
instance name is used to identify the instance, especially when
<a class="reference internal" href="#admin-reverse-urls"><em>reversing admin URLs</em></a>. If no instance name is
provided, a default instance name of <tt class="docutils literal"><span class="pre">admin</span></tt> will be used.
See <a class="reference internal" href="#customizing-adminsite"><em>Customizing the AdminSite class</em></a> for an example of customizing the
<a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> class.</p>
</dd></dl>

<div class="section" id="s-adminsite-attributes">
<span id="adminsite-attributes"></span><h3><tt class="docutils literal"><span class="pre">AdminSite</span></tt> attributes<a class="headerlink" href="#adminsite-attributes" title="Permalink to this headline">¶</a></h3>
<p>Templates can override or extend base admin templates as described in
<a class="reference internal" href="#admin-overriding-templates"><em>Overriding admin templates</em></a>.</p>
<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.site_header">
<tt class="descclassname">AdminSite.</tt><tt class="descname">site_header</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.site_header" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The text to put at the top of each admin page, as an <tt class="docutils literal"><span class="pre">&lt;h1&gt;</span></tt> (a string).
By default, this is &#8220;Django administration&#8221;.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.site_title">
<tt class="descclassname">AdminSite.</tt><tt class="descname">site_title</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.site_title" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The text to put at the end of each admin page&#8217;s <tt class="docutils literal"><span class="pre">&lt;title&gt;</span></tt> (a string). By
default, this is &#8220;Django site admin&#8221;.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.index_title">
<tt class="descclassname">AdminSite.</tt><tt class="descname">index_title</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.index_title" title="Permalink to this definition">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 1.7.</span> </div>
<p>The text to put at the top of the admin index page (a string). By default,
this is &#8220;Site administration&#8221;.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.index_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">index_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.index_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site main index
view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.app_index_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">app_index_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.app_index_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site app index view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.login_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">login_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.login_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site login view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.login_form">
<tt class="descclassname">AdminSite.</tt><tt class="descname">login_form</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.login_form" title="Permalink to this definition">¶</a></dt>
<dd><p>Subclass of <a class="reference internal" href="../../../topics/auth/default.html#django.contrib.auth.forms.AuthenticationForm" title="django.contrib.auth.forms.AuthenticationForm"><tt class="xref py py-class docutils literal"><span class="pre">AuthenticationForm</span></tt></a> that
will be used by the admin site login view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.logout_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">logout_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.logout_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site logout view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.password_change_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">password_change_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.password_change_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site password
change view.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.contrib.admin.AdminSite.password_change_done_template">
<tt class="descclassname">AdminSite.</tt><tt class="descname">password_change_done_template</tt><a class="headerlink" href="#django.contrib.admin.AdminSite.password_change_done_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Path to a custom template that will be used by the admin site password
change done view.</p>
</dd></dl>

</div>
<div class="section" id="s-hooking-adminsite-instances-into-your-urlconf">
<span id="hooking-adminsite-instances-into-your-urlconf"></span><h3>Hooking <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instances into your URLconf<a class="headerlink" href="#hooking-adminsite-instances-into-your-urlconf" title="Permalink to this headline">¶</a></h3>
<p>The last step in setting up the Django admin is to hook your <tt class="docutils literal"><span class="pre">AdminSite</span></tt>
instance into your URLconf. Do this by pointing a given URL at the
<tt class="docutils literal"><span class="pre">AdminSite.urls</span></tt> method.</p>
<p>In this example, we register the default <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instance
<tt class="docutils literal"><span class="pre">django.contrib.admin.site</span></tt> at the URL <tt class="docutils literal"><span class="pre">/admin/</span></tt></p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># urls.py</span>
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span>
<span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^admin/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-customizing-the-adminsite-class">
<span id="s-customizing-adminsite"></span><span id="customizing-the-adminsite-class"></span><span id="customizing-adminsite"></span><h3>Customizing the <a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> class<a class="headerlink" href="#customizing-the-adminsite-class" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;d like to set up your own admin site with custom behavior, you&#8217;re free
to subclass <tt class="docutils literal"><span class="pre">AdminSite</span></tt> and override or add anything you like. Then, simply
create an instance of your <tt class="docutils literal"><span class="pre">AdminSite</span></tt> subclass (the same way you&#8217;d
instantiate any other Python class) and register your models and
<tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> subclasses with it instead of with the default site. Finally,
update <tt class="file docutils literal"><span class="pre">myproject/urls.py</span></tt> to reference your <a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> subclass.</p>
<div class="highlight-python"><div class="snippet-filename">myapp/admin.py</div>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.admin</span> <span class="kn">import</span> <span class="n">AdminSite</span>

<span class="kn">from</span> <span class="nn">.models</span> <span class="kn">import</span> <span class="n">MyModel</span>

<span class="k">class</span> <span class="nc">MyAdminSite</span><span class="p">(</span><span class="n">AdminSite</span><span class="p">):</span>
    <span class="n">site_header</span> <span class="o">=</span> <span class="s">&#39;Monty Python administration&#39;</span>

<span class="n">admin_site</span> <span class="o">=</span> <span class="n">MyAdminSite</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;myadmin&#39;</span><span class="p">)</span>
<span class="n">admin_site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">MyModel</span><span class="p">)</span>
</pre></div>
</div>
<div class="highlight-python"><div class="snippet-filename">myproject/urls.py</div>
<div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span>

<span class="kn">from</span> <span class="nn">myapp.admin</span> <span class="kn">import</span> <span class="n">admin_site</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^myadmin/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">admin_site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that you may not want autodiscovery of <tt class="docutils literal"><span class="pre">admin</span></tt> modules when using your
own <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instance since you will likely be importing all the per-app
<tt class="docutils literal"><span class="pre">admin</span></tt> modules in your <tt class="docutils literal"><span class="pre">myproject.admin</span></tt> module. This means you need to
put <tt class="docutils literal"><span class="pre">'django.contrib.admin.apps.SimpleAdminConfig'</span></tt> instead of
<tt class="docutils literal"><span class="pre">'django.contrib.admin'</span></tt> in your <a class="reference internal" href="../../settings.html#std:setting-INSTALLED_APPS"><tt class="xref std std-setting docutils literal"><span class="pre">INSTALLED_APPS</span></tt></a> setting.</p>
</div>
<div class="section" id="s-multiple-admin-sites-in-the-same-urlconf">
<span id="s-multiple-admin-sites"></span><span id="multiple-admin-sites-in-the-same-urlconf"></span><span id="multiple-admin-sites"></span><h3>Multiple admin sites in the same URLconf<a class="headerlink" href="#multiple-admin-sites-in-the-same-urlconf" title="Permalink to this headline">¶</a></h3>
<p>It&#8217;s easy to create multiple instances of the admin site on the same
Django-powered Web site. Just create multiple instances of <tt class="docutils literal"><span class="pre">AdminSite</span></tt> and
root each one at a different URL.</p>
<p>In this example, the URLs <tt class="docutils literal"><span class="pre">/basic-admin/</span></tt> and <tt class="docutils literal"><span class="pre">/advanced-admin/</span></tt> feature
separate versions of the admin site &#8211; using the <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instances
<tt class="docutils literal"><span class="pre">myproject.admin.basic_site</span></tt> and <tt class="docutils literal"><span class="pre">myproject.admin.advanced_site</span></tt>,
respectively:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># urls.py</span>
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span>
<span class="kn">from</span> <span class="nn">myproject.admin</span> <span class="kn">import</span> <span class="n">basic_site</span><span class="p">,</span> <span class="n">advanced_site</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^basic-admin/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">basic_site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),</span>
    <span class="p">(</span><span class="s">r&#39;^advanced-admin/&#39;</span><span class="p">,</span> <span class="n">include</span><span class="p">(</span><span class="n">advanced_site</span><span class="o">.</span><span class="n">urls</span><span class="p">)),</span>
<span class="p">)</span>
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">AdminSite</span></tt> instances take a single argument to their constructor, their
name, which can be anything you like. This argument becomes the prefix to the
URL names for the purposes of <a class="reference internal" href="#admin-reverse-urls"><em>reversing them</em></a>. This
is only necessary if you are using more than one <tt class="docutils literal"><span class="pre">AdminSite</span></tt>.</p>
</div>
<div class="section" id="s-adding-views-to-admin-sites">
<span id="adding-views-to-admin-sites"></span><h3>Adding views to admin sites<a class="headerlink" href="#adding-views-to-admin-sites" title="Permalink to this headline">¶</a></h3>
<p>Just like <a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a>, <a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> provides a
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_urls" title="django.contrib.admin.ModelAdmin.get_urls"><tt class="xref py py-meth docutils literal"><span class="pre">get_urls()</span></tt></a> method
that can be overridden to define additional views for the site. To add
a new view to your admin site, extend the base
<a class="reference internal" href="#django.contrib.admin.ModelAdmin.get_urls" title="django.contrib.admin.ModelAdmin.get_urls"><tt class="xref py py-meth docutils literal"><span class="pre">get_urls()</span></tt></a> method to include
a pattern for your new view.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Any view you render that uses the admin templates, or extends the base
admin template, should provide the <tt class="docutils literal"><span class="pre">current_app</span></tt> argument to
<a class="reference internal" href="../../templates/api.html#django.template.RequestContext" title="django.template.RequestContext"><tt class="xref py py-class docutils literal"><span class="pre">RequestContext</span></tt></a> or
<a class="reference internal" href="../../templates/api.html#django.template.Context" title="django.template.Context"><tt class="xref py py-class docutils literal"><span class="pre">Context</span></tt></a> when rendering the template.  It should
be set to either <tt class="docutils literal"><span class="pre">self.name</span></tt> if your view is on an <tt class="docutils literal"><span class="pre">AdminSite</span></tt> or
<tt class="docutils literal"><span class="pre">self.admin_site.name</span></tt> if your view is on a <tt class="docutils literal"><span class="pre">ModelAdmin</span></tt>.</p>
</div>
</div>
<div class="section" id="s-adding-a-password-reset-feature">
<span id="s-auth-password-reset"></span><span id="adding-a-password-reset-feature"></span><span id="auth-password-reset"></span><h3>Adding a password-reset feature<a class="headerlink" href="#adding-a-password-reset-feature" title="Permalink to this headline">¶</a></h3>
<p>You can add a password-reset feature to the admin site by adding a few lines to
your URLconf. Specifically, add these four patterns:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.auth</span> <span class="kn">import</span> <span class="n">views</span> <span class="k">as</span> <span class="n">auth_views</span>

<span class="n">url</span><span class="p">(</span><span class="s">r&#39;^admin/password_reset/$&#39;</span><span class="p">,</span> <span class="n">auth_views</span><span class="o">.</span><span class="n">password_reset</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;admin_password_reset&#39;</span><span class="p">),</span>
<span class="n">url</span><span class="p">(</span><span class="s">r&#39;^admin/password_reset/done/$&#39;</span><span class="p">,</span> <span class="n">auth_views</span><span class="o">.</span><span class="n">password_reset_done</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;password_reset_done&#39;</span><span class="p">),</span>
<span class="n">url</span><span class="p">(</span><span class="s">r&#39;^reset/(?P&lt;uidb64&gt;[0-9A-Za-z_\-]+)/(?P&lt;token&gt;.+)/$&#39;</span><span class="p">,</span> <span class="n">auth_views</span><span class="o">.</span><span class="n">password_reset_confirm</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;password_reset_confirm&#39;</span><span class="p">),</span>
<span class="n">url</span><span class="p">(</span><span class="s">r&#39;^reset/done/$&#39;</span><span class="p">,</span> <span class="n">auth_views</span><span class="o">.</span><span class="n">password_reset_complete</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;password_reset_complete&#39;</span><span class="p">),</span>
</pre></div>
</div>
<div class="versionchanged">
<span class="title">Changed in Django 1.6:</span> <p>The pattern for <a class="reference internal" href="../../../topics/auth/default.html#django.contrib.auth.views.password_reset_confirm" title="django.contrib.auth.views.password_reset_confirm"><tt class="xref py py-func docutils literal"><span class="pre">password_reset_confirm()</span></tt></a>
changed as the <tt class="docutils literal"><span class="pre">uid</span></tt> is now base 64 encoded.</p>
</div>
<p>(This assumes you&#8217;ve added the admin at <tt class="docutils literal"><span class="pre">admin/</span></tt> and requires that you put
the URLs starting with <tt class="docutils literal"><span class="pre">^admin/</span></tt> before the line that includes the admin app
itself).</p>
<p>The presence of the <tt class="docutils literal"><span class="pre">admin_password_reset</span></tt> named URL will cause a &#8220;forgotten
your password?&#8221; link to appear on the default admin log-in page under the
password box.</p>
</div>
</div>
<div class="section" id="s-reversing-admin-urls">
<span id="s-admin-reverse-urls"></span><span id="reversing-admin-urls"></span><span id="admin-reverse-urls"></span><h2>Reversing admin URLs<a class="headerlink" href="#reversing-admin-urls" title="Permalink to this headline">¶</a></h2>
<p>When an <a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> is deployed, the views provided by that site are
accessible using Django&#8217;s <a class="reference internal" href="../../../topics/http/urls.html#naming-url-patterns"><em>URL reversing system</em></a>.</p>
<p>The <a class="reference internal" href="#django.contrib.admin.AdminSite" title="django.contrib.admin.AdminSite"><tt class="xref py py-class docutils literal"><span class="pre">AdminSite</span></tt></a> provides the following named URL patterns:</p>
<table class="docutils">
<colgroup>
<col width="30%" />
<col width="29%" />
<col width="41%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Page</th>
<th class="head">URL name</th>
<th class="head">Parameters</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Index</td>
<td><tt class="docutils literal"><span class="pre">index</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>Logout</td>
<td><tt class="docutils literal"><span class="pre">logout</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>Password change</td>
<td><tt class="docutils literal"><span class="pre">password_change</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>Password change done</td>
<td><tt class="docutils literal"><span class="pre">password_change_done</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>i18n javascript</td>
<td><tt class="docutils literal"><span class="pre">jsi18n</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>Application index page</td>
<td><tt class="docutils literal"><span class="pre">app_list</span></tt></td>
<td><tt class="docutils literal"><span class="pre">app_label</span></tt></td>
</tr>
<tr class="row-even"><td>Redirect to object&#8217;s page</td>
<td><tt class="docutils literal"><span class="pre">view_on_site</span></tt></td>
<td><tt class="docutils literal"><span class="pre">content_type_id</span></tt>, <tt class="docutils literal"><span class="pre">object_id</span></tt></td>
</tr>
</tbody>
</table>
<p>Each <a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a> instance provides an additional set of named URLs:</p>
<table class="docutils">
<colgroup>
<col width="27%" />
<col width="57%" />
<col width="16%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Page</th>
<th class="head">URL name</th>
<th class="head">Parameters</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>Changelist</td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">app_label</span> <span class="pre">}}_{{</span> <span class="pre">model_name</span> <span class="pre">}}_changelist</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>Add</td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">app_label</span> <span class="pre">}}_{{</span> <span class="pre">model_name</span> <span class="pre">}}_add</span></tt></td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>History</td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">app_label</span> <span class="pre">}}_{{</span> <span class="pre">model_name</span> <span class="pre">}}_history</span></tt></td>
<td><tt class="docutils literal"><span class="pre">object_id</span></tt></td>
</tr>
<tr class="row-odd"><td>Delete</td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">app_label</span> <span class="pre">}}_{{</span> <span class="pre">model_name</span> <span class="pre">}}_delete</span></tt></td>
<td><tt class="docutils literal"><span class="pre">object_id</span></tt></td>
</tr>
<tr class="row-even"><td>Change</td>
<td><tt class="docutils literal"><span class="pre">{{</span> <span class="pre">app_label</span> <span class="pre">}}_{{</span> <span class="pre">model_name</span> <span class="pre">}}_change</span></tt></td>
<td><tt class="docutils literal"><span class="pre">object_id</span></tt></td>
</tr>
</tbody>
</table>
<p>These named URLs are registered with the application namespace <tt class="docutils literal"><span class="pre">admin</span></tt>, and
with an instance namespace corresponding to the name of the Site instance.</p>
<p>So - if you wanted to get a reference to the Change view for a particular
<tt class="docutils literal"><span class="pre">Choice</span></tt> object (from the polls application) in the default admin, you would
call:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.core</span> <span class="kn">import</span> <span class="n">urlresolvers</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">c</span> <span class="o">=</span> <span class="n">Choice</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">change_url</span> <span class="o">=</span> <span class="n">urlresolvers</span><span class="o">.</span><span class="n">reverse</span><span class="p">(</span><span class="s">&#39;admin:polls_choice_change&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">,))</span>
</pre></div>
</div>
<p>This will find the first registered instance of the admin application
(whatever the instance name), and resolve to the view for changing
<tt class="docutils literal"><span class="pre">poll.Choice</span></tt> instances in that instance.</p>
<p>If you want to find a URL in a specific admin instance, provide the name of
that instance as a <tt class="docutils literal"><span class="pre">current_app</span></tt> hint to the reverse call. For example,
if you specifically wanted the admin view from the admin instance named
<tt class="docutils literal"><span class="pre">custom</span></tt>, you would need to call:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">change_url</span> <span class="o">=</span> <span class="n">urlresolvers</span><span class="o">.</span><span class="n">reverse</span><span class="p">(</span><span class="s">&#39;admin:polls_choice_change&#39;</span><span class="p">,</span>
<span class="gp">... </span>                                  <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">,),</span> <span class="n">current_app</span><span class="o">=</span><span class="s">&#39;custom&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>For more details, see the documentation on <a class="reference internal" href="../../../topics/http/urls.html#topics-http-reversing-url-namespaces"><em>reversing namespaced URLs</em></a>.</p>
<p>To allow easier reversing of the admin urls in templates, Django provides an
<tt class="docutils literal"><span class="pre">admin_urlname</span></tt> filter which takes an action as argument:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">load</span> <span class="nv">admin_urls</span> <span class="cp">%}</span>
<span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">url</span> <span class="nv">opts</span><span class="o">|</span><span class="nf">admin_urlname</span><span class="s1">:&#39;add&#39;</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="nt">&gt;</span>Add user<span class="nt">&lt;/a&gt;</span>
<span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;</span><span class="cp">{%</span> <span class="k">url</span> <span class="nv">opts</span><span class="o">|</span><span class="nf">admin_urlname</span><span class="s1">:&#39;delete&#39;</span> <span class="nv">user.pk</span> <span class="cp">%}</span><span class="s">&quot;</span><span class="nt">&gt;</span>Delete this user<span class="nt">&lt;/a&gt;</span>
</pre></div>
</div>
<p>The action in the examples above match the last part of the URL names for
<a class="reference internal" href="#django.contrib.admin.ModelAdmin" title="django.contrib.admin.ModelAdmin"><tt class="xref py py-class docutils literal"><span class="pre">ModelAdmin</span></tt></a> instances described above. The <tt class="docutils literal"><span class="pre">opts</span></tt> variable can be any
object which has an <tt class="docutils literal"><span class="pre">app_label</span></tt> and <tt class="docutils literal"><span class="pre">model_name</span></tt> attributes and is usually
supplied by the admin views for the current model.</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The Django admin site</a><ul>
<li><a class="reference internal" href="#overview">Overview</a><ul>
<li><a class="reference internal" href="#other-topics">Other topics</a></li>
</ul>
</li>
<li><a class="reference internal" href="#modeladmin-objects"><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> objects</a><ul>
<li><a class="reference internal" href="#the-register-decorator">The register decorator</a></li>
<li><a class="reference internal" href="#discovery-of-admin-files">Discovery of admin files</a></li>
<li><a class="reference internal" href="#modeladmin-options"><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> options</a><ul>
<li><a class="reference internal" href="#custom-template-options">Custom template options</a></li>
</ul>
</li>
<li><a class="reference internal" href="#modeladmin-methods"><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> methods</a><ul>
<li><a class="reference internal" href="#other-methods">Other methods</a></li>
</ul>
</li>
<li><a class="reference internal" href="#modeladmin-asset-definitions"><tt class="docutils literal"><span class="pre">ModelAdmin</span></tt> asset definitions</a><ul>
<li><a class="reference internal" href="#jquery">jQuery</a></li>
</ul>
</li>
<li><a class="reference internal" href="#adding-custom-validation-to-the-admin">Adding custom validation to the admin</a></li>
</ul>
</li>
<li><a class="reference internal" href="#inlinemodeladmin-objects"><tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> objects</a><ul>
<li><a class="reference internal" href="#inlinemodeladmin-options"><tt class="docutils literal"><span class="pre">InlineModelAdmin</span></tt> options</a></li>
<li><a class="reference internal" href="#working-with-a-model-with-two-or-more-foreign-keys-to-the-same-parent-model">Working with a model with two or more foreign keys to the same parent model</a></li>
<li><a class="reference internal" href="#working-with-many-to-many-models">Working with many-to-many models</a></li>
<li><a class="reference internal" href="#working-with-many-to-many-intermediary-models">Working with many-to-many intermediary models</a></li>
<li><a class="reference internal" href="#using-generic-relations-as-an-inline">Using generic relations as an inline</a></li>
</ul>
</li>
<li><a class="reference internal" href="#overriding-admin-templates">Overriding admin templates</a><ul>
<li><a class="reference internal" href="#set-up-your-projects-admin-template-directories">Set up your projects admin template directories</a></li>
<li><a class="reference internal" href="#overriding-vs-replacing-an-admin-template">Overriding vs. replacing an admin template</a></li>
<li><a class="reference internal" href="#templates-which-may-be-overridden-per-app-or-model">Templates which may be overridden per app or model</a></li>
<li><a class="reference internal" href="#root-and-login-templates">Root and login templates</a></li>
</ul>
</li>
<li><a class="reference internal" href="#adminsite-objects"><tt class="docutils literal"><span class="pre">AdminSite</span></tt> objects</a><ul>
<li><a class="reference internal" href="#adminsite-attributes"><tt class="docutils literal"><span class="pre">AdminSite</span></tt> attributes</a></li>
<li><a class="reference internal" href="#hooking-adminsite-instances-into-your-urlconf">Hooking <tt class="docutils literal"><span class="pre">AdminSite</span></tt> instances into your URLconf</a></li>
<li><a class="reference internal" href="#customizing-the-adminsite-class">Customizing the <tt class="docutils literal"><span class="pre">AdminSite</span></tt> class</a></li>
<li><a class="reference internal" href="#multiple-admin-sites-in-the-same-urlconf">Multiple admin sites in the same URLconf</a></li>
<li><a class="reference internal" href="#adding-views-to-admin-sites">Adding views to admin sites</a></li>
<li><a class="reference internal" href="#adding-a-password-reset-feature">Adding a password-reset feature</a></li>
</ul>
</li>
<li><a class="reference internal" href="#reversing-admin-urls">Reversing admin URLs</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="../index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a></li>
    
    
      <li>Next: <a href="actions.html">Admin actions</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../../index.html">API Reference</a>
        
          <ul><li><a href="../index.html"><tt class="docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
        <ul><li>The Django admin site</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/ref/contrib/admin/index.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="../index.html" title="&lt;tt class=&#34;docutils literal&#34;&gt;&lt;span class=&#34;pre&#34;&gt;contrib&lt;/span&gt;&lt;/tt&gt; packages">previous</a>
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="actions.html" title="Admin actions">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>